1 //
   2 // Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   3 // DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4 //
   5 // This code is free software; you can redistribute it and/or modify it
   6 // under the terms of the GNU General Public License version 2 only, as
   7 // published by the Free Software Foundation.
   8 //
   9 // This code is distributed in the hope that it will be useful, but WITHOUT
  10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12 // version 2 for more details (a copy is included in the LICENSE file that
  13 // accompanied this code).
  14 //
  15 // You should have received a copy of the GNU General Public License version
  16 // 2 along with this work; if not, write to the Free Software Foundation,
  17 // Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18 //
  19 // Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20 // or visit www.oracle.com if you need additional information or have any
  21 // questions.
  22 //
  23 //
  24 
  25 // AMD64 Architecture Description File
  26 
  27 //----------REGISTER DEFINITION BLOCK------------------------------------------
  28 // This information is used by the matcher and the register allocator to
  29 // describe individual registers and classes of registers within the target
  30 // archtecture.
  31 
  32 register %{
  33 //----------Architecture Description Register Definitions----------------------
  34 // General Registers
  35 // "reg_def"  name ( register save type, C convention save type,
  36 //                   ideal register type, encoding );
  37 // Register Save Types:
  38 //
  39 // NS  = No-Save:       The register allocator assumes that these registers
  40 //                      can be used without saving upon entry to the method, &
  41 //                      that they do not need to be saved at call sites.
  42 //
  43 // SOC = Save-On-Call:  The register allocator assumes that these registers
  44 //                      can be used without saving upon entry to the method,
  45 //                      but that they must be saved at call sites.
  46 //
  47 // SOE = Save-On-Entry: The register allocator assumes that these registers
  48 //                      must be saved before using them upon entry to the
  49 //                      method, but they do not need to be saved at call
  50 //                      sites.
  51 //
  52 // AS  = Always-Save:   The register allocator assumes that these registers
  53 //                      must be saved before using them upon entry to the
  54 //                      method, & that they must be saved at call sites.
  55 //
  56 // Ideal Register Type is used to determine how to save & restore a
  57 // register.  Op_RegI will get spilled with LoadI/StoreI, Op_RegP will get
  58 // spilled with LoadP/StoreP.  If the register supports both, use Op_RegI.
  59 //
  60 // The encoding number is the actual bit-pattern placed into the opcodes.
  61 
  62 // General Registers
  63 // R8-R15 must be encoded with REX.  (RSP, RBP, RSI, RDI need REX when
  64 // used as byte registers)
  65 
  66 // Previously set RBX, RSI, and RDI as save-on-entry for java code
  67 // Turn off SOE in java-code due to frequent use of uncommon-traps.
  68 // Now that allocator is better, turn on RSI and RDI as SOE registers.
  69 
  70 reg_def RAX  (SOC, SOC, Op_RegI,  0, rax->as_VMReg());
  71 reg_def RAX_H(SOC, SOC, Op_RegI,  0, rax->as_VMReg()->next());
  72 
  73 reg_def RCX  (SOC, SOC, Op_RegI,  1, rcx->as_VMReg());
  74 reg_def RCX_H(SOC, SOC, Op_RegI,  1, rcx->as_VMReg()->next());
  75 
  76 reg_def RDX  (SOC, SOC, Op_RegI,  2, rdx->as_VMReg());
  77 reg_def RDX_H(SOC, SOC, Op_RegI,  2, rdx->as_VMReg()->next());
  78 
  79 reg_def RBX  (SOC, SOE, Op_RegI,  3, rbx->as_VMReg());
  80 reg_def RBX_H(SOC, SOE, Op_RegI,  3, rbx->as_VMReg()->next());
  81 
  82 reg_def RSP  (NS,  NS,  Op_RegI,  4, rsp->as_VMReg());
  83 reg_def RSP_H(NS,  NS,  Op_RegI,  4, rsp->as_VMReg()->next());
  84 
  85 // now that adapter frames are gone RBP is always saved and restored by the prolog/epilog code
  86 reg_def RBP  (NS, SOE, Op_RegI,  5, rbp->as_VMReg());
  87 reg_def RBP_H(NS, SOE, Op_RegI,  5, rbp->as_VMReg()->next());
  88 
  89 #ifdef _WIN64
  90 
  91 reg_def RSI  (SOC, SOE, Op_RegI,  6, rsi->as_VMReg());
  92 reg_def RSI_H(SOC, SOE, Op_RegI,  6, rsi->as_VMReg()->next());
  93 
  94 reg_def RDI  (SOC, SOE, Op_RegI,  7, rdi->as_VMReg());
  95 reg_def RDI_H(SOC, SOE, Op_RegI,  7, rdi->as_VMReg()->next());
  96 
  97 #else
  98 
  99 reg_def RSI  (SOC, SOC, Op_RegI,  6, rsi->as_VMReg());
 100 reg_def RSI_H(SOC, SOC, Op_RegI,  6, rsi->as_VMReg()->next());
 101 
 102 reg_def RDI  (SOC, SOC, Op_RegI,  7, rdi->as_VMReg());
 103 reg_def RDI_H(SOC, SOC, Op_RegI,  7, rdi->as_VMReg()->next());
 104 
 105 #endif
 106 
 107 reg_def R8   (SOC, SOC, Op_RegI,  8, r8->as_VMReg());
 108 reg_def R8_H (SOC, SOC, Op_RegI,  8, r8->as_VMReg()->next());
 109 
 110 reg_def R9   (SOC, SOC, Op_RegI,  9, r9->as_VMReg());
 111 reg_def R9_H (SOC, SOC, Op_RegI,  9, r9->as_VMReg()->next());
 112 
 113 reg_def R10  (SOC, SOC, Op_RegI, 10, r10->as_VMReg());
 114 reg_def R10_H(SOC, SOC, Op_RegI, 10, r10->as_VMReg()->next());
 115 
 116 reg_def R11  (SOC, SOC, Op_RegI, 11, r11->as_VMReg());
 117 reg_def R11_H(SOC, SOC, Op_RegI, 11, r11->as_VMReg()->next());
 118 
 119 reg_def R12  (SOC, SOE, Op_RegI, 12, r12->as_VMReg());
 120 reg_def R12_H(SOC, SOE, Op_RegI, 12, r12->as_VMReg()->next());
 121 
 122 reg_def R13  (SOC, SOE, Op_RegI, 13, r13->as_VMReg());
 123 reg_def R13_H(SOC, SOE, Op_RegI, 13, r13->as_VMReg()->next());
 124 
 125 reg_def R14  (SOC, SOE, Op_RegI, 14, r14->as_VMReg());
 126 reg_def R14_H(SOC, SOE, Op_RegI, 14, r14->as_VMReg()->next());
 127 
 128 reg_def R15  (SOC, SOE, Op_RegI, 15, r15->as_VMReg());
 129 reg_def R15_H(SOC, SOE, Op_RegI, 15, r15->as_VMReg()->next());
 130 
 131 
 132 // Floating Point Registers
 133 
 134 // 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
 143 
 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());
 146 
 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());
 149 
 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());
 152 
 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());
 155 
 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());
 158 
 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());
 161 
 162 #ifdef _WIN64
 163 
 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());
 166 
 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());
 169 
 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());
 172 
 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());
 175 
 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());
 178 
 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());
 181 
 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());
 184 
 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());
 187 
 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());
 190 
 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());
 193 
 194 #else
 195 
 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());
 198 
 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());
 201 
 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());
 204 
 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());
 207 
 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());
 210 
 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());
 213 
 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());
 216 
 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());
 219 
 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());
 222 
 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());
 225 
 226 #endif // _WIN64
 227 
 228 reg_def RFLAGS(SOC, SOC, 0, 16, VMRegImpl::Bad());
 229 
 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.
 237 
 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);
 254 
 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);
 272 
 273 alloc_class chunk2(RFLAGS);
 274 
 275 
 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 //
 284 
 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);
 302 
 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);
 317 
 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                          R13, R13_H,
 330                          R14, R14_H);
 331 
 332 reg_class ptr_no_rbp_reg(RDX, RDX_H,
 333                          RAX, RAX_H,
 334                          RDI, RDI_H,
 335                          RSI, RSI_H,
 336                          RCX, RCX_H,
 337                          RBX, RBX_H,
 338                          R8,  R8_H,
 339                          R9,  R9_H,
 340                          R10, R10_H,
 341                          R11, R11_H,
 342                          R13, R13_H,
 343                          R14, R14_H);
 344 
 345 // Class for all pointer registers except RAX, RBX and RSP
 346 reg_class ptr_no_rax_rbx_reg(RDX, RDX_H,
 347                              RBP, RBP_H,
 348                              RDI, RDI_H,
 349                              RSI, RSI_H,
 350                              RCX, RCX_H,
 351                              R8,  R8_H,
 352                              R9,  R9_H,
 353                              R10, R10_H,
 354                              R11, R11_H,
 355                              R13, R13_H,
 356                              R14, R14_H);
 357 
 358 // Singleton class for RAX pointer register
 359 reg_class ptr_rax_reg(RAX, RAX_H);
 360 
 361 // Singleton class for RBX pointer register
 362 reg_class ptr_rbx_reg(RBX, RBX_H);
 363 
 364 // Singleton class for RSI pointer register
 365 reg_class ptr_rsi_reg(RSI, RSI_H);
 366 
 367 // Singleton class for RDI pointer register
 368 reg_class ptr_rdi_reg(RDI, RDI_H);
 369 
 370 // Singleton class for RBP pointer register
 371 reg_class ptr_rbp_reg(RBP, RBP_H);
 372 
 373 // Singleton class for stack pointer
 374 reg_class ptr_rsp_reg(RSP, RSP_H);
 375 
 376 // Singleton class for TLS pointer
 377 reg_class ptr_r15_reg(R15, R15_H);
 378 
 379 // Class for all long registers (except RSP)
 380 reg_class long_reg(RAX, RAX_H,
 381                    RDX, RDX_H,
 382                    RBP, RBP_H,
 383                    RDI, RDI_H,
 384                    RSI, RSI_H,
 385                    RCX, RCX_H,
 386                    RBX, RBX_H,
 387                    R8,  R8_H,
 388                    R9,  R9_H,
 389                    R10, R10_H,
 390                    R11, R11_H,
 391                    R13, R13_H,
 392                    R14, R14_H);
 393 
 394 // Class for all long registers except RAX, RDX (and RSP)
 395 reg_class long_no_rax_rdx_reg(RBP, RBP_H,
 396                               RDI, RDI_H,
 397                               RSI, RSI_H,
 398                               RCX, RCX_H,
 399                               RBX, RBX_H,
 400                               R8,  R8_H,
 401                               R9,  R9_H,
 402                               R10, R10_H,
 403                               R11, R11_H,
 404                               R13, R13_H,
 405                               R14, R14_H);
 406 
 407 // Class for all long registers except RCX (and RSP)
 408 reg_class long_no_rcx_reg(RBP, RBP_H,
 409                           RDI, RDI_H,
 410                           RSI, RSI_H,
 411                           RAX, RAX_H,
 412                           RDX, RDX_H,
 413                           RBX, RBX_H,
 414                           R8,  R8_H,
 415                           R9,  R9_H,
 416                           R10, R10_H,
 417                           R11, R11_H,
 418                           R13, R13_H,
 419                           R14, R14_H);
 420 
 421 // Class for all long registers except RAX (and RSP)
 422 reg_class long_no_rax_reg(RBP, RBP_H,
 423                           RDX, RDX_H,
 424                           RDI, RDI_H,
 425                           RSI, RSI_H,
 426                           RCX, RCX_H,
 427                           RBX, RBX_H,
 428                           R8,  R8_H,
 429                           R9,  R9_H,
 430                           R10, R10_H,
 431                           R11, R11_H,
 432                           R13, R13_H,
 433                           R14, R14_H);
 434 
 435 // Singleton class for RAX long register
 436 reg_class long_rax_reg(RAX, RAX_H);
 437 
 438 // Singleton class for RCX long register
 439 reg_class long_rcx_reg(RCX, RCX_H);
 440 
 441 // Singleton class for RDX long register
 442 reg_class long_rdx_reg(RDX, RDX_H);
 443 
 444 // Class for all int registers (except RSP)
 445 reg_class int_reg(RAX,
 446                   RDX,
 447                   RBP,
 448                   RDI,
 449                   RSI,
 450                   RCX,
 451                   RBX,
 452                   R8,
 453                   R9,
 454                   R10,
 455                   R11,
 456                   R13,
 457                   R14);
 458 
 459 // Class for all int registers except RCX (and RSP)
 460 reg_class int_no_rcx_reg(RAX,
 461                          RDX,
 462                          RBP,
 463                          RDI,
 464                          RSI,
 465                          RBX,
 466                          R8,
 467                          R9,
 468                          R10,
 469                          R11,
 470                          R13,
 471                          R14);
 472 
 473 // Class for all int registers except RAX, RDX (and RSP)
 474 reg_class int_no_rax_rdx_reg(RBP,
 475                              RDI,
 476                              RSI,
 477                              RCX,
 478                              RBX,
 479                              R8,
 480                              R9,
 481                              R10,
 482                              R11,
 483                              R13,
 484                              R14);
 485 
 486 // Singleton class for RAX int register
 487 reg_class int_rax_reg(RAX);
 488 
 489 // Singleton class for RBX int register
 490 reg_class int_rbx_reg(RBX);
 491 
 492 // Singleton class for RCX int register
 493 reg_class int_rcx_reg(RCX);
 494 
 495 // Singleton class for RCX int register
 496 reg_class int_rdx_reg(RDX);
 497 
 498 // Singleton class for RCX int register
 499 reg_class int_rdi_reg(RDI);
 500 
 501 // Singleton class for instruction pointer
 502 // reg_class ip_reg(RIP);
 503 
 504 // Singleton class for condition codes
 505 reg_class int_flags(RFLAGS);
 506 
 507 // Class for all float registers
 508 reg_class float_reg(XMM0,
 509                     XMM1,
 510                     XMM2,
 511                     XMM3,
 512                     XMM4,
 513                     XMM5,
 514                     XMM6,
 515                     XMM7,
 516                     XMM8,
 517                     XMM9,
 518                     XMM10,
 519                     XMM11,
 520                     XMM12,
 521                     XMM13,
 522                     XMM14,
 523                     XMM15);
 524 
 525 // Class for all double registers
 526 reg_class double_reg(XMM0,  XMM0_H,
 527                      XMM1,  XMM1_H,
 528                      XMM2,  XMM2_H,
 529                      XMM3,  XMM3_H,
 530                      XMM4,  XMM4_H,
 531                      XMM5,  XMM5_H,
 532                      XMM6,  XMM6_H,
 533                      XMM7,  XMM7_H,
 534                      XMM8,  XMM8_H,
 535                      XMM9,  XMM9_H,
 536                      XMM10, XMM10_H,
 537                      XMM11, XMM11_H,
 538                      XMM12, XMM12_H,
 539                      XMM13, XMM13_H,
 540                      XMM14, XMM14_H,
 541                      XMM15, XMM15_H);
 542 %}
 543 
 544 
 545 //----------SOURCE BLOCK-------------------------------------------------------
 546 // This is a block of C++ code which provides values, functions, and
 547 // definitions necessary in the rest of the architecture description
 548 source %{
 549 #define   RELOC_IMM64    Assembler::imm_operand
 550 #define   RELOC_DISP32   Assembler::disp32_operand
 551 
 552 #define __ _masm.
 553 
 554 static int preserve_SP_size() {
 555   return LP64_ONLY(1 +) 2;  // [rex,] op, rm(reg/reg)
 556 }
 557 
 558 // !!!!! Special hack to get all types of calls to specify the byte offset
 559 //       from the start of the call to the point where the return address
 560 //       will point.
 561 int MachCallStaticJavaNode::ret_addr_offset()
 562 {
 563   int offset = 5; // 5 bytes from start of call to where return address points
 564   if (_method_handle_invoke)
 565     offset += preserve_SP_size();
 566   return offset;
 567 }
 568 
 569 int MachCallDynamicJavaNode::ret_addr_offset()
 570 {
 571   return 15; // 15 bytes from start of call to where return address points
 572 }
 573 
 574 // In os_cpu .ad file
 575 // int MachCallRuntimeNode::ret_addr_offset()
 576 
 577 // Indicate if the safepoint node needs the polling page as an input,
 578 // it does if the polling page is more than disp32 away.
 579 bool SafePointNode::needs_polling_address_input()
 580 {
 581   return Assembler::is_polling_page_far();
 582 }
 583 
 584 //
 585 // Compute padding required for nodes which need alignment
 586 //
 587 
 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 }
 595 
 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 CallStaticJavaHandleNode::compute_padding(int current_offset) const
 599 {
 600   current_offset += preserve_SP_size();   // skip mov rbp, rsp
 601   current_offset += 1; // skip call opcode byte
 602   return round_to(current_offset, alignment_required()) - current_offset;
 603 }
 604 
 605 // The address of the call instruction needs to be 4-byte aligned to
 606 // ensure that it does not span a cache line so that it can be patched.
 607 int CallDynamicJavaDirectNode::compute_padding(int current_offset) const
 608 {
 609   current_offset += 11; // skip movq instruction + call opcode byte
 610   return round_to(current_offset, alignment_required()) - current_offset;
 611 }
 612 
 613 #ifndef PRODUCT
 614 void MachBreakpointNode::format(PhaseRegAlloc*, outputStream* st) const
 615 {
 616   st->print("INT3");
 617 }
 618 #endif
 619 
 620 // EMIT_RM()
 621 void emit_rm(CodeBuffer &cbuf, int f1, int f2, int f3) {
 622   unsigned char c = (unsigned char) ((f1 << 6) | (f2 << 3) | f3);
 623   cbuf.insts()->emit_int8(c);
 624 }
 625 
 626 // EMIT_CC()
 627 void emit_cc(CodeBuffer &cbuf, int f1, int f2) {
 628   unsigned char c = (unsigned char) (f1 | f2);
 629   cbuf.insts()->emit_int8(c);
 630 }
 631 
 632 // EMIT_OPCODE()
 633 void emit_opcode(CodeBuffer &cbuf, int code) {
 634   cbuf.insts()->emit_int8((unsigned char) code);
 635 }
 636 
 637 // EMIT_OPCODE() w/ relocation information
 638 void emit_opcode(CodeBuffer &cbuf,
 639                  int code, relocInfo::relocType reloc, int offset, int format)
 640 {
 641   cbuf.relocate(cbuf.insts_mark() + offset, reloc, format);
 642   emit_opcode(cbuf, code);
 643 }
 644 
 645 // EMIT_D8()
 646 void emit_d8(CodeBuffer &cbuf, int d8) {
 647   cbuf.insts()->emit_int8((unsigned char) d8);
 648 }
 649 
 650 // EMIT_D16()
 651 void emit_d16(CodeBuffer &cbuf, int d16) {
 652   cbuf.insts()->emit_int16(d16);
 653 }
 654 
 655 // EMIT_D32()
 656 void emit_d32(CodeBuffer &cbuf, int d32) {
 657   cbuf.insts()->emit_int32(d32);
 658 }
 659 
 660 // EMIT_D64()
 661 void emit_d64(CodeBuffer &cbuf, int64_t d64) {
 662   cbuf.insts()->emit_int64(d64);
 663 }
 664 
 665 // emit 32 bit value and construct relocation entry from relocInfo::relocType
 666 void emit_d32_reloc(CodeBuffer& cbuf,
 667                     int d32,
 668                     relocInfo::relocType reloc,
 669                     int format)
 670 {
 671   assert(reloc != relocInfo::external_word_type, "use 2-arg emit_d32_reloc");
 672   cbuf.relocate(cbuf.insts_mark(), reloc, format);
 673   cbuf.insts()->emit_int32(d32);
 674 }
 675 
 676 // emit 32 bit value and construct relocation entry from RelocationHolder
 677 void emit_d32_reloc(CodeBuffer& cbuf, int d32, RelocationHolder const& rspec, int format) {
 678 #ifdef ASSERT
 679   if (rspec.reloc()->type() == relocInfo::oop_type &&
 680       d32 != 0 && d32 != (intptr_t) Universe::non_oop_word()) {
 681     assert(oop((intptr_t)d32)->is_oop() && (ScavengeRootsInCode || !oop((intptr_t)d32)->is_scavengable()), "cannot embed scavengable oops in code");
 682   }
 683 #endif
 684   cbuf.relocate(cbuf.insts_mark(), rspec, format);
 685   cbuf.insts()->emit_int32(d32);
 686 }
 687 
 688 void emit_d32_reloc(CodeBuffer& cbuf, address addr) {
 689   address next_ip = cbuf.insts_end() + 4;
 690   emit_d32_reloc(cbuf, (int) (addr - next_ip),
 691                  external_word_Relocation::spec(addr),
 692                  RELOC_DISP32);
 693 }
 694 
 695 
 696 // emit 64 bit value and construct relocation entry from relocInfo::relocType
 697 void emit_d64_reloc(CodeBuffer& cbuf, int64_t d64, relocInfo::relocType reloc, int format) {
 698   cbuf.relocate(cbuf.insts_mark(), reloc, format);
 699   cbuf.insts()->emit_int64(d64);
 700 }
 701 
 702 // emit 64 bit value and construct relocation entry from RelocationHolder
 703 void emit_d64_reloc(CodeBuffer& cbuf, int64_t d64, RelocationHolder const& rspec, int format) {
 704 #ifdef ASSERT
 705   if (rspec.reloc()->type() == relocInfo::oop_type &&
 706       d64 != 0 && d64 != (int64_t) Universe::non_oop_word()) {
 707     assert(oop(d64)->is_oop() && (ScavengeRootsInCode || !oop(d64)->is_scavengable()),
 708            "cannot embed scavengable oops in code");
 709   }
 710 #endif
 711   cbuf.relocate(cbuf.insts_mark(), rspec, format);
 712   cbuf.insts()->emit_int64(d64);
 713 }
 714 
 715 // Access stack slot for load or store
 716 void store_to_stackslot(CodeBuffer &cbuf, int opcode, int rm_field, int disp)
 717 {
 718   emit_opcode(cbuf, opcode);                  // (e.g., FILD   [RSP+src])
 719   if (-0x80 <= disp && disp < 0x80) {
 720     emit_rm(cbuf, 0x01, rm_field, RSP_enc);   // R/M byte
 721     emit_rm(cbuf, 0x00, RSP_enc, RSP_enc);    // SIB byte
 722     emit_d8(cbuf, disp);     // Displacement  // R/M byte
 723   } else {
 724     emit_rm(cbuf, 0x02, rm_field, RSP_enc);   // R/M byte
 725     emit_rm(cbuf, 0x00, RSP_enc, RSP_enc);    // SIB byte
 726     emit_d32(cbuf, disp);     // Displacement // R/M byte
 727   }
 728 }
 729 
 730    // rRegI ereg, memory mem) %{    // emit_reg_mem
 731 void encode_RegMem(CodeBuffer &cbuf,
 732                    int reg,
 733                    int base, int index, int scale, int disp, bool disp_is_oop)
 734 {
 735   assert(!disp_is_oop, "cannot have disp");
 736   int regenc = reg & 7;
 737   int baseenc = base & 7;
 738   int indexenc = index & 7;
 739 
 740   // There is no index & no scale, use form without SIB byte
 741   if (index == 0x4 && scale == 0 && base != RSP_enc && base != R12_enc) {
 742     // If no displacement, mode is 0x0; unless base is [RBP] or [R13]
 743     if (disp == 0 && base != RBP_enc && base != R13_enc) {
 744       emit_rm(cbuf, 0x0, regenc, baseenc); // *
 745     } else if (-0x80 <= disp && disp < 0x80 && !disp_is_oop) {
 746       // If 8-bit displacement, mode 0x1
 747       emit_rm(cbuf, 0x1, regenc, baseenc); // *
 748       emit_d8(cbuf, disp);
 749     } else {
 750       // If 32-bit displacement
 751       if (base == -1) { // Special flag for absolute address
 752         emit_rm(cbuf, 0x0, regenc, 0x5); // *
 753         if (disp_is_oop) {
 754           emit_d32_reloc(cbuf, disp, relocInfo::oop_type, RELOC_DISP32);
 755         } else {
 756           emit_d32(cbuf, disp);
 757         }
 758       } else {
 759         // Normal base + offset
 760         emit_rm(cbuf, 0x2, regenc, baseenc); // *
 761         if (disp_is_oop) {
 762           emit_d32_reloc(cbuf, disp, relocInfo::oop_type, RELOC_DISP32);
 763         } else {
 764           emit_d32(cbuf, disp);
 765         }
 766       }
 767     }
 768   } else {
 769     // Else, encode with the SIB byte
 770     // If no displacement, mode is 0x0; unless base is [RBP] or [R13]
 771     if (disp == 0 && base != RBP_enc && base != R13_enc) {
 772       // If no displacement
 773       emit_rm(cbuf, 0x0, regenc, 0x4); // *
 774       emit_rm(cbuf, scale, indexenc, baseenc);
 775     } else {
 776       if (-0x80 <= disp && disp < 0x80 && !disp_is_oop) {
 777         // If 8-bit displacement, mode 0x1
 778         emit_rm(cbuf, 0x1, regenc, 0x4); // *
 779         emit_rm(cbuf, scale, indexenc, baseenc);
 780         emit_d8(cbuf, disp);
 781       } else {
 782         // If 32-bit displacement
 783         if (base == 0x04 ) {
 784           emit_rm(cbuf, 0x2, regenc, 0x4);
 785           emit_rm(cbuf, scale, indexenc, 0x04); // XXX is this valid???
 786         } else {
 787           emit_rm(cbuf, 0x2, regenc, 0x4);
 788           emit_rm(cbuf, scale, indexenc, baseenc); // *
 789         }
 790         if (disp_is_oop) {
 791           emit_d32_reloc(cbuf, disp, relocInfo::oop_type, RELOC_DISP32);
 792         } else {
 793           emit_d32(cbuf, disp);
 794         }
 795       }
 796     }
 797   }
 798 }
 799 
 800 void encode_copy(CodeBuffer &cbuf, int dstenc, int srcenc)
 801 {
 802   if (dstenc != srcenc) {
 803     if (dstenc < 8) {
 804       if (srcenc >= 8) {
 805         emit_opcode(cbuf, Assembler::REX_B);
 806         srcenc -= 8;
 807       }
 808     } else {
 809       if (srcenc < 8) {
 810         emit_opcode(cbuf, Assembler::REX_R);
 811       } else {
 812         emit_opcode(cbuf, Assembler::REX_RB);
 813         srcenc -= 8;
 814       }
 815       dstenc -= 8;
 816     }
 817 
 818     emit_opcode(cbuf, 0x8B);
 819     emit_rm(cbuf, 0x3, dstenc, srcenc);
 820   }
 821 }
 822 
 823 void encode_CopyXD( CodeBuffer &cbuf, int dst_encoding, int src_encoding ) {
 824   if( dst_encoding == src_encoding ) {
 825     // reg-reg copy, use an empty encoding
 826   } else {
 827     MacroAssembler _masm(&cbuf);
 828 
 829     __ movdqa(as_XMMRegister(dst_encoding), as_XMMRegister(src_encoding));
 830   }
 831 }
 832 
 833 // This could be in MacroAssembler but it's fairly C2 specific
 834 void emit_cmpfp_fixup(MacroAssembler& _masm) {
 835   Label exit;
 836   __ jccb(Assembler::noParity, exit);
 837   __ pushf();
 838   __ andq(Address(rsp, 0), 0xffffff2b);
 839   __ popf();
 840   __ bind(exit);
 841   __ nop(); // (target for branch to avoid branch to branch)
 842 }
 843 
 844 
 845 //=============================================================================
 846 const bool Matcher::constant_table_absolute_addressing = true;
 847 const RegMask& MachConstantBaseNode::_out_RegMask = RegMask::Empty;
 848 
 849 void MachConstantBaseNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const {
 850   // Empty encoding
 851 }
 852 
 853 uint MachConstantBaseNode::size(PhaseRegAlloc* ra_) const {
 854   return 0;
 855 }
 856 
 857 #ifndef PRODUCT
 858 void MachConstantBaseNode::format(PhaseRegAlloc* ra_, outputStream* st) const {
 859   st->print("# MachConstantBaseNode (empty encoding)");
 860 }
 861 #endif
 862 
 863 
 864 //=============================================================================
 865 #ifndef PRODUCT
 866 void MachPrologNode::format(PhaseRegAlloc* ra_, outputStream* st) const
 867 {
 868   Compile* C = ra_->C;
 869 
 870   int framesize = C->frame_slots() << LogBytesPerInt;
 871   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
 872   // Remove wordSize for return adr already pushed
 873   // and another for the RBP we are going to save
 874   framesize -= 2*wordSize;
 875   bool need_nop = true;
 876 
 877   // Calls to C2R adapters often do not accept exceptional returns.
 878   // We require that their callers must bang for them.  But be
 879   // careful, because some VM calls (such as call site linkage) can
 880   // use several kilobytes of stack.  But the stack safety zone should
 881   // account for that.  See bugs 4446381, 4468289, 4497237.
 882   if (C->need_stack_bang(framesize)) {
 883     st->print_cr("# stack bang"); st->print("\t");
 884     need_nop = false;
 885   }
 886   st->print_cr("pushq   rbp"); st->print("\t");
 887 
 888   if (VerifyStackAtCalls) {
 889     // Majik cookie to verify stack depth
 890     st->print_cr("pushq   0xffffffffbadb100d"
 891                   "\t# Majik cookie for stack depth check");
 892     st->print("\t");
 893     framesize -= wordSize; // Remove 2 for cookie
 894     need_nop = false;
 895   }
 896 
 897   if (framesize) {
 898     st->print("subq    rsp, #%d\t# Create frame", framesize);
 899     if (framesize < 0x80 && need_nop) {
 900       st->print("\n\tnop\t# nop for patch_verified_entry");
 901     }
 902   }
 903 }
 904 #endif
 905 
 906 void MachPrologNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const
 907 {
 908   Compile* C = ra_->C;
 909 
 910   // WARNING: Initial instruction MUST be 5 bytes or longer so that
 911   // NativeJump::patch_verified_entry will be able to patch out the entry
 912   // code safely. The fldcw is ok at 6 bytes, the push to verify stack
 913   // depth is ok at 5 bytes, the frame allocation can be either 3 or
 914   // 6 bytes. So if we don't do the fldcw or the push then we must
 915   // use the 6 byte frame allocation even if we have no frame. :-(
 916   // If method sets FPU control word do it now
 917 
 918   int framesize = C->frame_slots() << LogBytesPerInt;
 919   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
 920   // Remove wordSize for return adr already pushed
 921   // and another for the RBP we are going to save
 922   framesize -= 2*wordSize;
 923   bool need_nop = true;
 924 
 925   // Calls to C2R adapters often do not accept exceptional returns.
 926   // We require that their callers must bang for them.  But be
 927   // careful, because some VM calls (such as call site linkage) can
 928   // use several kilobytes of stack.  But the stack safety zone should
 929   // account for that.  See bugs 4446381, 4468289, 4497237.
 930   if (C->need_stack_bang(framesize)) {
 931     MacroAssembler masm(&cbuf);
 932     masm.generate_stack_overflow_check(framesize);
 933     need_nop = false;
 934   }
 935 
 936   // We always push rbp so that on return to interpreter rbp will be
 937   // restored correctly and we can correct the stack.
 938   emit_opcode(cbuf, 0x50 | RBP_enc);
 939 
 940   if (VerifyStackAtCalls) {
 941     // Majik cookie to verify stack depth
 942     emit_opcode(cbuf, 0x68); // pushq (sign-extended) 0xbadb100d
 943     emit_d32(cbuf, 0xbadb100d);
 944     framesize -= wordSize; // Remove 2 for cookie
 945     need_nop = false;
 946   }
 947 
 948   if (framesize) {
 949     emit_opcode(cbuf, Assembler::REX_W);
 950     if (framesize < 0x80) {
 951       emit_opcode(cbuf, 0x83);   // sub  SP,#framesize
 952       emit_rm(cbuf, 0x3, 0x05, RSP_enc);
 953       emit_d8(cbuf, framesize);
 954       if (need_nop) {
 955         emit_opcode(cbuf, 0x90); // nop
 956       }
 957     } else {
 958       emit_opcode(cbuf, 0x81);   // sub  SP,#framesize
 959       emit_rm(cbuf, 0x3, 0x05, RSP_enc);
 960       emit_d32(cbuf, framesize);
 961     }
 962   }
 963 
 964   C->set_frame_complete(cbuf.insts_size());
 965 
 966 #ifdef ASSERT
 967   if (VerifyStackAtCalls) {
 968     Label L;
 969     MacroAssembler masm(&cbuf);
 970     masm.push(rax);
 971     masm.mov(rax, rsp);
 972     masm.andptr(rax, StackAlignmentInBytes-1);
 973     masm.cmpptr(rax, StackAlignmentInBytes-wordSize);
 974     masm.pop(rax);
 975     masm.jcc(Assembler::equal, L);
 976     masm.stop("Stack is not properly aligned!");
 977     masm.bind(L);
 978   }
 979 #endif
 980 }
 981 
 982 uint MachPrologNode::size(PhaseRegAlloc* ra_) const
 983 {
 984   return MachNode::size(ra_); // too many variables; just compute it
 985                               // the hard way
 986 }
 987 
 988 int MachPrologNode::reloc() const
 989 {
 990   return 0; // a large enough number
 991 }
 992 
 993 //=============================================================================
 994 #ifndef PRODUCT
 995 void MachEpilogNode::format(PhaseRegAlloc* ra_, outputStream* st) const
 996 {
 997   Compile* C = ra_->C;
 998   int framesize = C->frame_slots() << LogBytesPerInt;
 999   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
1000   // Remove word for return adr already pushed
1001   // and RBP
1002   framesize -= 2*wordSize;
1003 
1004   if (framesize) {
1005     st->print_cr("addq    rsp, %d\t# Destroy frame", framesize);
1006     st->print("\t");
1007   }
1008 
1009   st->print_cr("popq   rbp");
1010   if (do_polling() && C->is_method_compilation()) {
1011     st->print("\t");
1012     if (Assembler::is_polling_page_far()) {
1013       st->print_cr("movq   rscratch1, #polling_page_address\n\t"
1014                    "testl  rax, [rscratch1]\t"
1015                    "# Safepoint: poll for GC");
1016     } else {
1017       st->print_cr("testl  rax, [rip + #offset_to_poll_page]\t"
1018                    "# Safepoint: poll for GC");
1019     }
1020   }
1021 }
1022 #endif
1023 
1024 void MachEpilogNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const
1025 {
1026   Compile* C = ra_->C;
1027   int framesize = C->frame_slots() << LogBytesPerInt;
1028   assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
1029   // Remove word for return adr already pushed
1030   // and RBP
1031   framesize -= 2*wordSize;
1032 
1033   // Note that VerifyStackAtCalls' Majik cookie does not change the frame size popped here
1034 
1035   if (framesize) {
1036     emit_opcode(cbuf, Assembler::REX_W);
1037     if (framesize < 0x80) {
1038       emit_opcode(cbuf, 0x83); // addq rsp, #framesize
1039       emit_rm(cbuf, 0x3, 0x00, RSP_enc);
1040       emit_d8(cbuf, framesize);
1041     } else {
1042       emit_opcode(cbuf, 0x81); // addq rsp, #framesize
1043       emit_rm(cbuf, 0x3, 0x00, RSP_enc);
1044       emit_d32(cbuf, framesize);
1045     }
1046   }
1047 
1048   // popq rbp
1049   emit_opcode(cbuf, 0x58 | RBP_enc);
1050 
1051   if (do_polling() && C->is_method_compilation()) {
1052     MacroAssembler _masm(&cbuf);
1053     AddressLiteral polling_page(os::get_polling_page(), relocInfo::poll_return_type);
1054     if (Assembler::is_polling_page_far()) {
1055       __ lea(rscratch1, polling_page);
1056       __ relocate(relocInfo::poll_return_type);
1057       __ testl(rax, Address(rscratch1, 0));
1058     } else {
1059       __ testl(rax, polling_page);
1060     }
1061   }
1062 }
1063 
1064 uint MachEpilogNode::size(PhaseRegAlloc* ra_) const
1065 {
1066   return MachNode::size(ra_); // too many variables; just compute it
1067                               // the hard way
1068 }
1069 
1070 int MachEpilogNode::reloc() const
1071 {
1072   return 2; // a large enough number
1073 }
1074 
1075 const Pipeline* MachEpilogNode::pipeline() const
1076 {
1077   return MachNode::pipeline_class();
1078 }
1079 
1080 int MachEpilogNode::safepoint_offset() const
1081 {
1082   return 0;
1083 }
1084 
1085 //=============================================================================
1086 
1087 enum RC {
1088   rc_bad,
1089   rc_int,
1090   rc_float,
1091   rc_stack
1092 };
1093 
1094 static enum RC rc_class(OptoReg::Name reg)
1095 {
1096   if( !OptoReg::is_valid(reg)  ) return rc_bad;
1097 
1098   if (OptoReg::is_stack(reg)) return rc_stack;
1099 
1100   VMReg r = OptoReg::as_VMReg(reg);
1101 
1102   if (r->is_Register()) return rc_int;
1103 
1104   assert(r->is_XMMRegister(), "must be");
1105   return rc_float;
1106 }
1107 
1108 uint MachSpillCopyNode::implementation(CodeBuffer* cbuf,
1109                                        PhaseRegAlloc* ra_,
1110                                        bool do_size,
1111                                        outputStream* st) const
1112 {
1113 
1114   // Get registers to move
1115   OptoReg::Name src_second = ra_->get_reg_second(in(1));
1116   OptoReg::Name src_first = ra_->get_reg_first(in(1));
1117   OptoReg::Name dst_second = ra_->get_reg_second(this);
1118   OptoReg::Name dst_first = ra_->get_reg_first(this);
1119 
1120   enum RC src_second_rc = rc_class(src_second);
1121   enum RC src_first_rc = rc_class(src_first);
1122   enum RC dst_second_rc = rc_class(dst_second);
1123   enum RC dst_first_rc = rc_class(dst_first);
1124 
1125   assert(OptoReg::is_valid(src_first) && OptoReg::is_valid(dst_first),
1126          "must move at least 1 register" );
1127 
1128   if (src_first == dst_first && src_second == dst_second) {
1129     // Self copy, no move
1130     return 0;
1131   } else if (src_first_rc == rc_stack) {
1132     // mem ->
1133     if (dst_first_rc == rc_stack) {
1134       // mem -> mem
1135       assert(src_second != dst_first, "overlap");
1136       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
1137           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
1138         // 64-bit
1139         int src_offset = ra_->reg2offset(src_first);
1140         int dst_offset = ra_->reg2offset(dst_first);
1141         if (cbuf) {
1142           emit_opcode(*cbuf, 0xFF);
1143           encode_RegMem(*cbuf, RSI_enc, RSP_enc, 0x4, 0, src_offset, false);
1144 
1145           emit_opcode(*cbuf, 0x8F);
1146           encode_RegMem(*cbuf, RAX_enc, RSP_enc, 0x4, 0, dst_offset, false);
1147 
1148 #ifndef PRODUCT
1149         } else if (!do_size) {
1150           st->print("pushq   [rsp + #%d]\t# 64-bit mem-mem spill\n\t"
1151                      "popq    [rsp + #%d]",
1152                      src_offset,
1153                      dst_offset);
1154 #endif
1155         }
1156         return
1157           3 + ((src_offset == 0) ? 0 : (src_offset < 0x80 ? 1 : 4)) +
1158           3 + ((dst_offset == 0) ? 0 : (dst_offset < 0x80 ? 1 : 4));
1159       } else {
1160         // 32-bit
1161         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
1162         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
1163         // No pushl/popl, so:
1164         int src_offset = ra_->reg2offset(src_first);
1165         int dst_offset = ra_->reg2offset(dst_first);
1166         if (cbuf) {
1167           emit_opcode(*cbuf, Assembler::REX_W);
1168           emit_opcode(*cbuf, 0x89);
1169           emit_opcode(*cbuf, 0x44);
1170           emit_opcode(*cbuf, 0x24);
1171           emit_opcode(*cbuf, 0xF8);
1172 
1173           emit_opcode(*cbuf, 0x8B);
1174           encode_RegMem(*cbuf,
1175                         RAX_enc,
1176                         RSP_enc, 0x4, 0, src_offset,
1177                         false);
1178 
1179           emit_opcode(*cbuf, 0x89);
1180           encode_RegMem(*cbuf,
1181                         RAX_enc,
1182                         RSP_enc, 0x4, 0, dst_offset,
1183                         false);
1184 
1185           emit_opcode(*cbuf, Assembler::REX_W);
1186           emit_opcode(*cbuf, 0x8B);
1187           emit_opcode(*cbuf, 0x44);
1188           emit_opcode(*cbuf, 0x24);
1189           emit_opcode(*cbuf, 0xF8);
1190 
1191 #ifndef PRODUCT
1192         } else if (!do_size) {
1193           st->print("movq    [rsp - #8], rax\t# 32-bit mem-mem spill\n\t"
1194                      "movl    rax, [rsp + #%d]\n\t"
1195                      "movl    [rsp + #%d], rax\n\t"
1196                      "movq    rax, [rsp - #8]",
1197                      src_offset,
1198                      dst_offset);
1199 #endif
1200         }
1201         return
1202           5 + // movq
1203           3 + ((src_offset == 0) ? 0 : (src_offset < 0x80 ? 1 : 4)) + // movl
1204           3 + ((dst_offset == 0) ? 0 : (dst_offset < 0x80 ? 1 : 4)) + // movl
1205           5; // movq
1206       }
1207     } else if (dst_first_rc == rc_int) {
1208       // mem -> gpr
1209       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
1210           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
1211         // 64-bit
1212         int offset = ra_->reg2offset(src_first);
1213         if (cbuf) {
1214           if (Matcher::_regEncode[dst_first] < 8) {
1215             emit_opcode(*cbuf, Assembler::REX_W);
1216           } else {
1217             emit_opcode(*cbuf, Assembler::REX_WR);
1218           }
1219           emit_opcode(*cbuf, 0x8B);
1220           encode_RegMem(*cbuf,
1221                         Matcher::_regEncode[dst_first],
1222                         RSP_enc, 0x4, 0, offset,
1223                         false);
1224 #ifndef PRODUCT
1225         } else if (!do_size) {
1226           st->print("movq    %s, [rsp + #%d]\t# spill",
1227                      Matcher::regName[dst_first],
1228                      offset);
1229 #endif
1230         }
1231         return
1232           ((offset == 0) ? 0 : (offset < 0x80 ? 1 : 4)) + 4; // REX
1233       } else {
1234         // 32-bit
1235         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
1236         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
1237         int offset = ra_->reg2offset(src_first);
1238         if (cbuf) {
1239           if (Matcher::_regEncode[dst_first] >= 8) {
1240             emit_opcode(*cbuf, Assembler::REX_R);
1241           }
1242           emit_opcode(*cbuf, 0x8B);
1243           encode_RegMem(*cbuf,
1244                         Matcher::_regEncode[dst_first],
1245                         RSP_enc, 0x4, 0, offset,
1246                         false);
1247 #ifndef PRODUCT
1248         } else if (!do_size) {
1249           st->print("movl    %s, [rsp + #%d]\t# spill",
1250                      Matcher::regName[dst_first],
1251                      offset);
1252 #endif
1253         }
1254         return
1255           ((offset == 0) ? 0 : (offset < 0x80 ? 1 : 4)) +
1256           ((Matcher::_regEncode[dst_first] < 8)
1257            ? 3
1258            : 4); // REX
1259       }
1260     } else if (dst_first_rc == rc_float) {
1261       // mem-> xmm
1262       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
1263           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
1264         // 64-bit
1265         int offset = ra_->reg2offset(src_first);
1266         if (cbuf) {
1267           emit_opcode(*cbuf, UseXmmLoadAndClearUpper ? 0xF2 : 0x66);
1268           if (Matcher::_regEncode[dst_first] >= 8) {
1269             emit_opcode(*cbuf, Assembler::REX_R);
1270           }
1271           emit_opcode(*cbuf, 0x0F);
1272           emit_opcode(*cbuf, UseXmmLoadAndClearUpper ? 0x10 : 0x12);
1273           encode_RegMem(*cbuf,
1274                         Matcher::_regEncode[dst_first],
1275                         RSP_enc, 0x4, 0, offset,
1276                         false);
1277 #ifndef PRODUCT
1278         } else if (!do_size) {
1279           st->print("%s  %s, [rsp + #%d]\t# spill",
1280                      UseXmmLoadAndClearUpper ? "movsd " : "movlpd",
1281                      Matcher::regName[dst_first],
1282                      offset);
1283 #endif
1284         }
1285         return
1286           ((offset == 0) ? 0 : (offset < 0x80 ? 1 : 4)) +
1287           ((Matcher::_regEncode[dst_first] < 8)
1288            ? 5
1289            : 6); // REX
1290       } else {
1291         // 32-bit
1292         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
1293         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
1294         int offset = ra_->reg2offset(src_first);
1295         if (cbuf) {
1296           emit_opcode(*cbuf, 0xF3);
1297           if (Matcher::_regEncode[dst_first] >= 8) {
1298             emit_opcode(*cbuf, Assembler::REX_R);
1299           }
1300           emit_opcode(*cbuf, 0x0F);
1301           emit_opcode(*cbuf, 0x10);
1302           encode_RegMem(*cbuf,
1303                         Matcher::_regEncode[dst_first],
1304                         RSP_enc, 0x4, 0, offset,
1305                         false);
1306 #ifndef PRODUCT
1307         } else if (!do_size) {
1308           st->print("movss   %s, [rsp + #%d]\t# spill",
1309                      Matcher::regName[dst_first],
1310                      offset);
1311 #endif
1312         }
1313         return
1314           ((offset == 0) ? 0 : (offset < 0x80 ? 1 : 4)) +
1315           ((Matcher::_regEncode[dst_first] < 8)
1316            ? 5
1317            : 6); // REX
1318       }
1319     }
1320   } else if (src_first_rc == rc_int) {
1321     // gpr ->
1322     if (dst_first_rc == rc_stack) {
1323       // gpr -> mem
1324       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
1325           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
1326         // 64-bit
1327         int offset = ra_->reg2offset(dst_first);
1328         if (cbuf) {
1329           if (Matcher::_regEncode[src_first] < 8) {
1330             emit_opcode(*cbuf, Assembler::REX_W);
1331           } else {
1332             emit_opcode(*cbuf, Assembler::REX_WR);
1333           }
1334           emit_opcode(*cbuf, 0x89);
1335           encode_RegMem(*cbuf,
1336                         Matcher::_regEncode[src_first],
1337                         RSP_enc, 0x4, 0, offset,
1338                         false);
1339 #ifndef PRODUCT
1340         } else if (!do_size) {
1341           st->print("movq    [rsp + #%d], %s\t# spill",
1342                      offset,
1343                      Matcher::regName[src_first]);
1344 #endif
1345         }
1346         return ((offset == 0) ? 0 : (offset < 0x80 ? 1 : 4)) + 4; // REX
1347       } else {
1348         // 32-bit
1349         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
1350         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
1351         int offset = ra_->reg2offset(dst_first);
1352         if (cbuf) {
1353           if (Matcher::_regEncode[src_first] >= 8) {
1354             emit_opcode(*cbuf, Assembler::REX_R);
1355           }
1356           emit_opcode(*cbuf, 0x89);
1357           encode_RegMem(*cbuf,
1358                         Matcher::_regEncode[src_first],
1359                         RSP_enc, 0x4, 0, offset,
1360                         false);
1361 #ifndef PRODUCT
1362         } else if (!do_size) {
1363           st->print("movl    [rsp + #%d], %s\t# spill",
1364                      offset,
1365                      Matcher::regName[src_first]);
1366 #endif
1367         }
1368         return
1369           ((offset == 0) ? 0 : (offset < 0x80 ? 1 : 4)) +
1370           ((Matcher::_regEncode[src_first] < 8)
1371            ? 3
1372            : 4); // REX
1373       }
1374     } else if (dst_first_rc == rc_int) {
1375       // gpr -> gpr
1376       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
1377           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
1378         // 64-bit
1379         if (cbuf) {
1380           if (Matcher::_regEncode[dst_first] < 8) {
1381             if (Matcher::_regEncode[src_first] < 8) {
1382               emit_opcode(*cbuf, Assembler::REX_W);
1383             } else {
1384               emit_opcode(*cbuf, Assembler::REX_WB);
1385             }
1386           } else {
1387             if (Matcher::_regEncode[src_first] < 8) {
1388               emit_opcode(*cbuf, Assembler::REX_WR);
1389             } else {
1390               emit_opcode(*cbuf, Assembler::REX_WRB);
1391             }
1392           }
1393           emit_opcode(*cbuf, 0x8B);
1394           emit_rm(*cbuf, 0x3,
1395                   Matcher::_regEncode[dst_first] & 7,
1396                   Matcher::_regEncode[src_first] & 7);
1397 #ifndef PRODUCT
1398         } else if (!do_size) {
1399           st->print("movq    %s, %s\t# spill",
1400                      Matcher::regName[dst_first],
1401                      Matcher::regName[src_first]);
1402 #endif
1403         }
1404         return 3; // REX
1405       } else {
1406         // 32-bit
1407         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
1408         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
1409         if (cbuf) {
1410           if (Matcher::_regEncode[dst_first] < 8) {
1411             if (Matcher::_regEncode[src_first] >= 8) {
1412               emit_opcode(*cbuf, Assembler::REX_B);
1413             }
1414           } else {
1415             if (Matcher::_regEncode[src_first] < 8) {
1416               emit_opcode(*cbuf, Assembler::REX_R);
1417             } else {
1418               emit_opcode(*cbuf, Assembler::REX_RB);
1419             }
1420           }
1421           emit_opcode(*cbuf, 0x8B);
1422           emit_rm(*cbuf, 0x3,
1423                   Matcher::_regEncode[dst_first] & 7,
1424                   Matcher::_regEncode[src_first] & 7);
1425 #ifndef PRODUCT
1426         } else if (!do_size) {
1427           st->print("movl    %s, %s\t# spill",
1428                      Matcher::regName[dst_first],
1429                      Matcher::regName[src_first]);
1430 #endif
1431         }
1432         return
1433           (Matcher::_regEncode[src_first] < 8 && Matcher::_regEncode[dst_first] < 8)
1434           ? 2
1435           : 3; // REX
1436       }
1437     } else if (dst_first_rc == rc_float) {
1438       // gpr -> xmm
1439       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
1440           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
1441         // 64-bit
1442         if (cbuf) {
1443           emit_opcode(*cbuf, 0x66);
1444           if (Matcher::_regEncode[dst_first] < 8) {
1445             if (Matcher::_regEncode[src_first] < 8) {
1446               emit_opcode(*cbuf, Assembler::REX_W);
1447             } else {
1448               emit_opcode(*cbuf, Assembler::REX_WB);
1449             }
1450           } else {
1451             if (Matcher::_regEncode[src_first] < 8) {
1452               emit_opcode(*cbuf, Assembler::REX_WR);
1453             } else {
1454               emit_opcode(*cbuf, Assembler::REX_WRB);
1455             }
1456           }
1457           emit_opcode(*cbuf, 0x0F);
1458           emit_opcode(*cbuf, 0x6E);
1459           emit_rm(*cbuf, 0x3,
1460                   Matcher::_regEncode[dst_first] & 7,
1461                   Matcher::_regEncode[src_first] & 7);
1462 #ifndef PRODUCT
1463         } else if (!do_size) {
1464           st->print("movdq   %s, %s\t# spill",
1465                      Matcher::regName[dst_first],
1466                      Matcher::regName[src_first]);
1467 #endif
1468         }
1469         return 5; // REX
1470       } else {
1471         // 32-bit
1472         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
1473         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
1474         if (cbuf) {
1475           emit_opcode(*cbuf, 0x66);
1476           if (Matcher::_regEncode[dst_first] < 8) {
1477             if (Matcher::_regEncode[src_first] >= 8) {
1478               emit_opcode(*cbuf, Assembler::REX_B);
1479             }
1480           } else {
1481             if (Matcher::_regEncode[src_first] < 8) {
1482               emit_opcode(*cbuf, Assembler::REX_R);
1483             } else {
1484               emit_opcode(*cbuf, Assembler::REX_RB);
1485             }
1486           }
1487           emit_opcode(*cbuf, 0x0F);
1488           emit_opcode(*cbuf, 0x6E);
1489           emit_rm(*cbuf, 0x3,
1490                   Matcher::_regEncode[dst_first] & 7,
1491                   Matcher::_regEncode[src_first] & 7);
1492 #ifndef PRODUCT
1493         } else if (!do_size) {
1494           st->print("movdl   %s, %s\t# spill",
1495                      Matcher::regName[dst_first],
1496                      Matcher::regName[src_first]);
1497 #endif
1498         }
1499         return
1500           (Matcher::_regEncode[src_first] < 8 && Matcher::_regEncode[dst_first] < 8)
1501           ? 4
1502           : 5; // REX
1503       }
1504     }
1505   } else if (src_first_rc == rc_float) {
1506     // xmm ->
1507     if (dst_first_rc == rc_stack) {
1508       // xmm -> mem
1509       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
1510           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
1511         // 64-bit
1512         int offset = ra_->reg2offset(dst_first);
1513         if (cbuf) {
1514           emit_opcode(*cbuf, 0xF2);
1515           if (Matcher::_regEncode[src_first] >= 8) {
1516               emit_opcode(*cbuf, Assembler::REX_R);
1517           }
1518           emit_opcode(*cbuf, 0x0F);
1519           emit_opcode(*cbuf, 0x11);
1520           encode_RegMem(*cbuf,
1521                         Matcher::_regEncode[src_first],
1522                         RSP_enc, 0x4, 0, offset,
1523                         false);
1524 #ifndef PRODUCT
1525         } else if (!do_size) {
1526           st->print("movsd   [rsp + #%d], %s\t# spill",
1527                      offset,
1528                      Matcher::regName[src_first]);
1529 #endif
1530         }
1531         return
1532           ((offset == 0) ? 0 : (offset < 0x80 ? 1 : 4)) +
1533           ((Matcher::_regEncode[src_first] < 8)
1534            ? 5
1535            : 6); // REX
1536       } else {
1537         // 32-bit
1538         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
1539         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
1540         int offset = ra_->reg2offset(dst_first);
1541         if (cbuf) {
1542           emit_opcode(*cbuf, 0xF3);
1543           if (Matcher::_regEncode[src_first] >= 8) {
1544               emit_opcode(*cbuf, Assembler::REX_R);
1545           }
1546           emit_opcode(*cbuf, 0x0F);
1547           emit_opcode(*cbuf, 0x11);
1548           encode_RegMem(*cbuf,
1549                         Matcher::_regEncode[src_first],
1550                         RSP_enc, 0x4, 0, offset,
1551                         false);
1552 #ifndef PRODUCT
1553         } else if (!do_size) {
1554           st->print("movss   [rsp + #%d], %s\t# spill",
1555                      offset,
1556                      Matcher::regName[src_first]);
1557 #endif
1558         }
1559         return
1560           ((offset == 0) ? 0 : (offset < 0x80 ? 1 : 4)) +
1561           ((Matcher::_regEncode[src_first] < 8)
1562            ? 5
1563            : 6); // REX
1564       }
1565     } else if (dst_first_rc == rc_int) {
1566       // xmm -> gpr
1567       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
1568           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
1569         // 64-bit
1570         if (cbuf) {
1571           emit_opcode(*cbuf, 0x66);
1572           if (Matcher::_regEncode[dst_first] < 8) {
1573             if (Matcher::_regEncode[src_first] < 8) {
1574               emit_opcode(*cbuf, Assembler::REX_W);
1575             } else {
1576               emit_opcode(*cbuf, Assembler::REX_WR); // attention!
1577             }
1578           } else {
1579             if (Matcher::_regEncode[src_first] < 8) {
1580               emit_opcode(*cbuf, Assembler::REX_WB); // attention!
1581             } else {
1582               emit_opcode(*cbuf, Assembler::REX_WRB);
1583             }
1584           }
1585           emit_opcode(*cbuf, 0x0F);
1586           emit_opcode(*cbuf, 0x7E);
1587           emit_rm(*cbuf, 0x3,
1588                   Matcher::_regEncode[src_first] & 7,
1589                   Matcher::_regEncode[dst_first] & 7);
1590 #ifndef PRODUCT
1591         } else if (!do_size) {
1592           st->print("movdq   %s, %s\t# spill",
1593                      Matcher::regName[dst_first],
1594                      Matcher::regName[src_first]);
1595 #endif
1596         }
1597         return 5; // REX
1598       } else {
1599         // 32-bit
1600         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
1601         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
1602         if (cbuf) {
1603           emit_opcode(*cbuf, 0x66);
1604           if (Matcher::_regEncode[dst_first] < 8) {
1605             if (Matcher::_regEncode[src_first] >= 8) {
1606               emit_opcode(*cbuf, Assembler::REX_R); // attention!
1607             }
1608           } else {
1609             if (Matcher::_regEncode[src_first] < 8) {
1610               emit_opcode(*cbuf, Assembler::REX_B); // attention!
1611             } else {
1612               emit_opcode(*cbuf, Assembler::REX_RB);
1613             }
1614           }
1615           emit_opcode(*cbuf, 0x0F);
1616           emit_opcode(*cbuf, 0x7E);
1617           emit_rm(*cbuf, 0x3,
1618                   Matcher::_regEncode[src_first] & 7,
1619                   Matcher::_regEncode[dst_first] & 7);
1620 #ifndef PRODUCT
1621         } else if (!do_size) {
1622           st->print("movdl   %s, %s\t# spill",
1623                      Matcher::regName[dst_first],
1624                      Matcher::regName[src_first]);
1625 #endif
1626         }
1627         return
1628           (Matcher::_regEncode[src_first] < 8 && Matcher::_regEncode[dst_first] < 8)
1629           ? 4
1630           : 5; // REX
1631       }
1632     } else if (dst_first_rc == rc_float) {
1633       // xmm -> xmm
1634       if ((src_first & 1) == 0 && src_first + 1 == src_second &&
1635           (dst_first & 1) == 0 && dst_first + 1 == dst_second) {
1636         // 64-bit
1637         if (cbuf) {
1638           emit_opcode(*cbuf, UseXmmRegToRegMoveAll ? 0x66 : 0xF2);
1639           if (Matcher::_regEncode[dst_first] < 8) {
1640             if (Matcher::_regEncode[src_first] >= 8) {
1641               emit_opcode(*cbuf, Assembler::REX_B);
1642             }
1643           } else {
1644             if (Matcher::_regEncode[src_first] < 8) {
1645               emit_opcode(*cbuf, Assembler::REX_R);
1646             } else {
1647               emit_opcode(*cbuf, Assembler::REX_RB);
1648             }
1649           }
1650           emit_opcode(*cbuf, 0x0F);
1651           emit_opcode(*cbuf, UseXmmRegToRegMoveAll ? 0x28 : 0x10);
1652           emit_rm(*cbuf, 0x3,
1653                   Matcher::_regEncode[dst_first] & 7,
1654                   Matcher::_regEncode[src_first] & 7);
1655 #ifndef PRODUCT
1656         } else if (!do_size) {
1657           st->print("%s  %s, %s\t# spill",
1658                      UseXmmRegToRegMoveAll ? "movapd" : "movsd ",
1659                      Matcher::regName[dst_first],
1660                      Matcher::regName[src_first]);
1661 #endif
1662         }
1663         return
1664           (Matcher::_regEncode[src_first] < 8 && Matcher::_regEncode[dst_first] < 8)
1665           ? 4
1666           : 5; // REX
1667       } else {
1668         // 32-bit
1669         assert(!((src_first & 1) == 0 && src_first + 1 == src_second), "no transform");
1670         assert(!((dst_first & 1) == 0 && dst_first + 1 == dst_second), "no transform");
1671         if (cbuf) {
1672           if (!UseXmmRegToRegMoveAll)
1673             emit_opcode(*cbuf, 0xF3);
1674           if (Matcher::_regEncode[dst_first] < 8) {
1675             if (Matcher::_regEncode[src_first] >= 8) {
1676               emit_opcode(*cbuf, Assembler::REX_B);
1677             }
1678           } else {
1679             if (Matcher::_regEncode[src_first] < 8) {
1680               emit_opcode(*cbuf, Assembler::REX_R);
1681             } else {
1682               emit_opcode(*cbuf, Assembler::REX_RB);
1683             }
1684           }
1685           emit_opcode(*cbuf, 0x0F);
1686           emit_opcode(*cbuf, UseXmmRegToRegMoveAll ? 0x28 : 0x10);
1687           emit_rm(*cbuf, 0x3,
1688                   Matcher::_regEncode[dst_first] & 7,
1689                   Matcher::_regEncode[src_first] & 7);
1690 #ifndef PRODUCT
1691         } else if (!do_size) {
1692           st->print("%s  %s, %s\t# spill",
1693                      UseXmmRegToRegMoveAll ? "movaps" : "movss ",
1694                      Matcher::regName[dst_first],
1695                      Matcher::regName[src_first]);
1696 #endif
1697         }
1698         return
1699           (Matcher::_regEncode[src_first] < 8 && Matcher::_regEncode[dst_first] < 8)
1700           ? (UseXmmRegToRegMoveAll ? 3 : 4)
1701           : (UseXmmRegToRegMoveAll ? 4 : 5); // REX
1702       }
1703     }
1704   }
1705 
1706   assert(0," foo ");
1707   Unimplemented();
1708 
1709   return 0;
1710 }
1711 
1712 #ifndef PRODUCT
1713 void MachSpillCopyNode::format(PhaseRegAlloc *ra_, outputStream* st) const
1714 {
1715   implementation(NULL, ra_, false, st);
1716 }
1717 #endif
1718 
1719 void MachSpillCopyNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const
1720 {
1721   implementation(&cbuf, ra_, false, NULL);
1722 }
1723 
1724 uint MachSpillCopyNode::size(PhaseRegAlloc *ra_) const
1725 {
1726   return implementation(NULL, ra_, true, NULL);
1727 }
1728 
1729 //=============================================================================
1730 #ifndef PRODUCT
1731 void MachNopNode::format(PhaseRegAlloc*, outputStream* st) const
1732 {
1733   st->print("nop \t# %d bytes pad for loops and calls", _count);
1734 }
1735 #endif
1736 
1737 void MachNopNode::emit(CodeBuffer &cbuf, PhaseRegAlloc*) const
1738 {
1739   MacroAssembler _masm(&cbuf);
1740   __ nop(_count);
1741 }
1742 
1743 uint MachNopNode::size(PhaseRegAlloc*) const
1744 {
1745   return _count;
1746 }
1747 
1748 
1749 //=============================================================================
1750 #ifndef PRODUCT
1751 void BoxLockNode::format(PhaseRegAlloc* ra_, outputStream* st) const
1752 {
1753   int offset = ra_->reg2offset(in_RegMask(0).find_first_elem());
1754   int reg = ra_->get_reg_first(this);
1755   st->print("leaq    %s, [rsp + #%d]\t# box lock",
1756             Matcher::regName[reg], offset);
1757 }
1758 #endif
1759 
1760 void BoxLockNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const
1761 {
1762   int offset = ra_->reg2offset(in_RegMask(0).find_first_elem());
1763   int reg = ra_->get_encode(this);
1764   if (offset >= 0x80) {
1765     emit_opcode(cbuf, reg < 8 ? Assembler::REX_W : Assembler::REX_WR);
1766     emit_opcode(cbuf, 0x8D); // LEA  reg,[SP+offset]
1767     emit_rm(cbuf, 0x2, reg & 7, 0x04);
1768     emit_rm(cbuf, 0x0, 0x04, RSP_enc);
1769     emit_d32(cbuf, offset);
1770   } else {
1771     emit_opcode(cbuf, reg < 8 ? Assembler::REX_W : Assembler::REX_WR);
1772     emit_opcode(cbuf, 0x8D); // LEA  reg,[SP+offset]
1773     emit_rm(cbuf, 0x1, reg & 7, 0x04);
1774     emit_rm(cbuf, 0x0, 0x04, RSP_enc);
1775     emit_d8(cbuf, offset);
1776   }
1777 }
1778 
1779 uint BoxLockNode::size(PhaseRegAlloc *ra_) const
1780 {
1781   int offset = ra_->reg2offset(in_RegMask(0).find_first_elem());
1782   return (offset < 0x80) ? 5 : 8; // REX
1783 }
1784 
1785 //=============================================================================
1786 
1787 // emit call stub, compiled java to interpreter
1788 void emit_java_to_interp(CodeBuffer& cbuf)
1789 {
1790   // Stub is fixed up when the corresponding call is converted from
1791   // calling compiled code to calling interpreted code.
1792   // movq rbx, 0
1793   // jmp -5 # to self
1794 
1795   address mark = cbuf.insts_mark();  // get mark within main instrs section
1796 
1797   // Note that the code buffer's insts_mark is always relative to insts.
1798   // That's why we must use the macroassembler to generate a stub.
1799   MacroAssembler _masm(&cbuf);
1800 
1801   address base =
1802   __ start_a_stub(Compile::MAX_stubs_size);
1803   if (base == NULL)  return;  // CodeBuffer::expand failed
1804   // static stub relocation stores the instruction address of the call
1805   __ relocate(static_stub_Relocation::spec(mark), RELOC_IMM64);
1806   // static stub relocation also tags the methodOop in the code-stream.
1807   __ movoop(rbx, (jobject) NULL);  // method is zapped till fixup time
1808   // This is recognized as unresolved by relocs/nativeinst/ic code
1809   __ jump(RuntimeAddress(__ pc()));
1810 
1811   // Update current stubs pointer and restore insts_end.
1812   __ end_a_stub();
1813 }
1814 
1815 // size of call stub, compiled java to interpretor
1816 uint size_java_to_interp()
1817 {
1818   return 15;  // movq (1+1+8); jmp (1+4)
1819 }
1820 
1821 // relocation entries for call stub, compiled java to interpretor
1822 uint reloc_java_to_interp()
1823 {
1824   return 4; // 3 in emit_java_to_interp + 1 in Java_Static_Call
1825 }
1826 
1827 //=============================================================================
1828 #ifndef PRODUCT
1829 void MachUEPNode::format(PhaseRegAlloc* ra_, outputStream* st) const
1830 {
1831   if (UseCompressedOops) {
1832     st->print_cr("movl    rscratch1, [j_rarg0 + oopDesc::klass_offset_in_bytes()]\t# compressed klass");
1833     if (Universe::narrow_oop_shift() != 0) {
1834       st->print_cr("\tdecode_heap_oop_not_null rscratch1, rscratch1");
1835     }
1836     st->print_cr("\tcmpq    rax, rscratch1\t # Inline cache check");
1837   } else {
1838     st->print_cr("\tcmpq    rax, [j_rarg0 + oopDesc::klass_offset_in_bytes()]\t"
1839                  "# Inline cache check");
1840   }
1841   st->print_cr("\tjne     SharedRuntime::_ic_miss_stub");
1842   st->print_cr("\tnop\t# nops to align entry point");
1843 }
1844 #endif
1845 
1846 void MachUEPNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const
1847 {
1848   MacroAssembler masm(&cbuf);
1849   uint insts_size = cbuf.insts_size();
1850   if (UseCompressedOops) {
1851     masm.load_klass(rscratch1, j_rarg0);
1852     masm.cmpptr(rax, rscratch1);
1853   } else {
1854     masm.cmpptr(rax, Address(j_rarg0, oopDesc::klass_offset_in_bytes()));
1855   }
1856 
1857   masm.jump_cc(Assembler::notEqual, RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
1858 
1859   /* WARNING these NOPs are critical so that verified entry point is properly
1860      4 bytes aligned for patching by NativeJump::patch_verified_entry() */
1861   int nops_cnt = 4 - ((cbuf.insts_size() - insts_size) & 0x3);
1862   if (OptoBreakpoint) {
1863     // Leave space for int3
1864     nops_cnt -= 1;
1865   }
1866   nops_cnt &= 0x3; // Do not add nops if code is aligned.
1867   if (nops_cnt > 0)
1868     masm.nop(nops_cnt);
1869 }
1870 
1871 uint MachUEPNode::size(PhaseRegAlloc* ra_) const
1872 {
1873   return MachNode::size(ra_); // too many variables; just compute it
1874                               // the hard way
1875 }
1876 
1877 
1878 //=============================================================================
1879 uint size_exception_handler()
1880 {
1881   // NativeCall instruction size is the same as NativeJump.
1882   // Note that this value is also credited (in output.cpp) to
1883   // the size of the code section.
1884   return NativeJump::instruction_size;
1885 }
1886 
1887 // Emit exception handler code.
1888 int emit_exception_handler(CodeBuffer& cbuf)
1889 {
1890 
1891   // Note that the code buffer's insts_mark is always relative to insts.
1892   // That's why we must use the macroassembler to generate a handler.
1893   MacroAssembler _masm(&cbuf);
1894   address base =
1895   __ start_a_stub(size_exception_handler());
1896   if (base == NULL)  return 0;  // CodeBuffer::expand failed
1897   int offset = __ offset();
1898   __ jump(RuntimeAddress(OptoRuntime::exception_blob()->entry_point()));
1899   assert(__ offset() - offset <= (int) size_exception_handler(), "overflow");
1900   __ end_a_stub();
1901   return offset;
1902 }
1903 
1904 uint size_deopt_handler()
1905 {
1906   // three 5 byte instructions
1907   return 15;
1908 }
1909 
1910 // Emit deopt handler code.
1911 int emit_deopt_handler(CodeBuffer& cbuf)
1912 {
1913 
1914   // Note that the code buffer's insts_mark is always relative to insts.
1915   // That's why we must use the macroassembler to generate a handler.
1916   MacroAssembler _masm(&cbuf);
1917   address base =
1918   __ start_a_stub(size_deopt_handler());
1919   if (base == NULL)  return 0;  // CodeBuffer::expand failed
1920   int offset = __ offset();
1921   address the_pc = (address) __ pc();
1922   Label next;
1923   // push a "the_pc" on the stack without destroying any registers
1924   // as they all may be live.
1925 
1926   // push address of "next"
1927   __ call(next, relocInfo::none); // reloc none is fine since it is a disp32
1928   __ bind(next);
1929   // adjust it so it matches "the_pc"
1930   __ subptr(Address(rsp, 0), __ offset() - offset);
1931   __ jump(RuntimeAddress(SharedRuntime::deopt_blob()->unpack()));
1932   assert(__ offset() - offset <= (int) size_deopt_handler(), "overflow");
1933   __ end_a_stub();
1934   return offset;
1935 }
1936 
1937 
1938 const bool Matcher::match_rule_supported(int opcode) {
1939   if (!has_match_rule(opcode))
1940     return false;
1941 
1942   return true;  // Per default match rules are supported.
1943 }
1944 
1945 int Matcher::regnum_to_fpu_offset(int regnum)
1946 {
1947   return regnum - 32; // The FP registers are in the second chunk
1948 }
1949 
1950 // This is UltraSparc specific, true just means we have fast l2f conversion
1951 const bool Matcher::convL2FSupported(void) {
1952   return true;
1953 }
1954 
1955 // Vector width in bytes
1956 const uint Matcher::vector_width_in_bytes(void) {
1957   return 8;
1958 }
1959 
1960 // Vector ideal reg
1961 const uint Matcher::vector_ideal_reg(void) {
1962   return Op_RegD;
1963 }
1964 
1965 // Is this branch offset short enough that a short branch can be used?
1966 //
1967 // NOTE: If the platform does not provide any short branch variants, then
1968 //       this method should return false for offset 0.
1969 bool Matcher::is_short_branch_offset(int rule, int offset) {
1970   // the short version of jmpConUCF2 contains multiple branches,
1971   // making the reach slightly less
1972   if (rule == jmpConUCF2_rule)
1973     return (-126 <= offset && offset <= 125);
1974   return (-128 <= offset && offset <= 127);
1975 }
1976 
1977 const bool Matcher::isSimpleConstant64(jlong value) {
1978   // Will one (StoreL ConL) be cheaper than two (StoreI ConI)?.
1979   //return value == (int) value;  // Cf. storeImmL and immL32.
1980 
1981   // Probably always true, even if a temp register is required.
1982   return true;
1983 }
1984 
1985 // The ecx parameter to rep stosq for the ClearArray node is in words.
1986 const bool Matcher::init_array_count_is_in_bytes = false;
1987 
1988 // Threshold size for cleararray.
1989 const int Matcher::init_array_short_size = 8 * BytesPerLong;
1990 
1991 // Should the Matcher clone shifts on addressing modes, expecting them
1992 // to be subsumed into complex addressing expressions or compute them
1993 // into registers?  True for Intel but false for most RISCs
1994 const bool Matcher::clone_shift_expressions = true;
1995 
1996 // Do we need to mask the count passed to shift instructions or does
1997 // the cpu only look at the lower 5/6 bits anyway?
1998 const bool Matcher::need_masked_shift_count = false;
1999 
2000 bool Matcher::narrow_oop_use_complex_address() {
2001   assert(UseCompressedOops, "only for compressed oops code");
2002   return (LogMinObjAlignmentInBytes <= 3);
2003 }
2004 
2005 // Is it better to copy float constants, or load them directly from
2006 // memory?  Intel can load a float constant from a direct address,
2007 // requiring no extra registers.  Most RISCs will have to materialize
2008 // an address into a register first, so they would do better to copy
2009 // the constant from stack.
2010 const bool Matcher::rematerialize_float_constants = true; // XXX
2011 
2012 // If CPU can load and store mis-aligned doubles directly then no
2013 // fixup is needed.  Else we split the double into 2 integer pieces
2014 // and move it piece-by-piece.  Only happens when passing doubles into
2015 // C code as the Java calling convention forces doubles to be aligned.
2016 const bool Matcher::misaligned_doubles_ok = true;
2017 
2018 // No-op on amd64
2019 void Matcher::pd_implicit_null_fixup(MachNode *node, uint idx) {}
2020 
2021 // Advertise here if the CPU requires explicit rounding operations to
2022 // implement the UseStrictFP mode.
2023 const bool Matcher::strict_fp_requires_explicit_rounding = true;
2024 
2025 // Are floats conerted to double when stored to stack during deoptimization?
2026 // On x64 it is stored without convertion so we can use normal access.
2027 bool Matcher::float_in_double() { return false; }
2028 
2029 // Do ints take an entire long register or just half?
2030 const bool Matcher::int_in_long = true;
2031 
2032 // Return whether or not this register is ever used as an argument.
2033 // This function is used on startup to build the trampoline stubs in
2034 // generateOptoStub.  Registers not mentioned will be killed by the VM
2035 // call in the trampoline, and arguments in those registers not be
2036 // available to the callee.
2037 bool Matcher::can_be_java_arg(int reg)
2038 {
2039   return
2040     reg ==  RDI_num || reg ==  RDI_H_num ||
2041     reg ==  RSI_num || reg ==  RSI_H_num ||
2042     reg ==  RDX_num || reg ==  RDX_H_num ||
2043     reg ==  RCX_num || reg ==  RCX_H_num ||
2044     reg ==   R8_num || reg ==   R8_H_num ||
2045     reg ==   R9_num || reg ==   R9_H_num ||
2046     reg ==  R12_num || reg ==  R12_H_num ||
2047     reg == XMM0_num || reg == XMM0_H_num ||
2048     reg == XMM1_num || reg == XMM1_H_num ||
2049     reg == XMM2_num || reg == XMM2_H_num ||
2050     reg == XMM3_num || reg == XMM3_H_num ||
2051     reg == XMM4_num || reg == XMM4_H_num ||
2052     reg == XMM5_num || reg == XMM5_H_num ||
2053     reg == XMM6_num || reg == XMM6_H_num ||
2054     reg == XMM7_num || reg == XMM7_H_num;
2055 }
2056 
2057 bool Matcher::is_spillable_arg(int reg)
2058 {
2059   return can_be_java_arg(reg);
2060 }
2061 
2062 bool Matcher::use_asm_for_ldiv_by_con( jlong divisor ) {
2063   // In 64 bit mode a code which use multiply when
2064   // devisor is constant is faster than hardware
2065   // DIV instruction (it uses MulHiL).
2066   return false;
2067 }
2068 
2069 // Register for DIVI projection of divmodI
2070 RegMask Matcher::divI_proj_mask() {
2071   return INT_RAX_REG_mask;
2072 }
2073 
2074 // Register for MODI projection of divmodI
2075 RegMask Matcher::modI_proj_mask() {
2076   return INT_RDX_REG_mask;
2077 }
2078 
2079 // Register for DIVL projection of divmodL
2080 RegMask Matcher::divL_proj_mask() {
2081   return LONG_RAX_REG_mask;
2082 }
2083 
2084 // Register for MODL projection of divmodL
2085 RegMask Matcher::modL_proj_mask() {
2086   return LONG_RDX_REG_mask;
2087 }
2088 
2089 const RegMask Matcher::method_handle_invoke_SP_save_mask() {
2090   return PTR_RBP_REG_mask;
2091 }
2092 
2093 static Address build_address(int b, int i, int s, int d) {
2094   Register index = as_Register(i);
2095   Address::ScaleFactor scale = (Address::ScaleFactor)s;
2096   if (index == rsp) {
2097     index = noreg;
2098     scale = Address::no_scale;
2099   }
2100   Address addr(as_Register(b), index, scale, d);
2101   return addr;
2102 }
2103 
2104 %}
2105 
2106 //----------ENCODING BLOCK-----------------------------------------------------
2107 // This block specifies the encoding classes used by the compiler to
2108 // output byte streams.  Encoding classes are parameterized macros
2109 // used by Machine Instruction Nodes in order to generate the bit
2110 // encoding of the instruction.  Operands specify their base encoding
2111 // interface with the interface keyword.  There are currently
2112 // supported four interfaces, REG_INTER, CONST_INTER, MEMORY_INTER, &
2113 // COND_INTER.  REG_INTER causes an operand to generate a function
2114 // which returns its register number when queried.  CONST_INTER causes
2115 // an operand to generate a function which returns the value of the
2116 // constant when queried.  MEMORY_INTER causes an operand to generate
2117 // four functions which return the Base Register, the Index Register,
2118 // the Scale Value, and the Offset Value of the operand when queried.
2119 // COND_INTER causes an operand to generate six functions which return
2120 // the encoding code (ie - encoding bits for the instruction)
2121 // associated with each basic boolean condition for a conditional
2122 // instruction.
2123 //
2124 // Instructions specify two basic values for encoding.  Again, a
2125 // function is available to check if the constant displacement is an
2126 // oop. They use the ins_encode keyword to specify their encoding
2127 // classes (which must be a sequence of enc_class names, and their
2128 // parameters, specified in the encoding block), and they use the
2129 // opcode keyword to specify, in order, their primary, secondary, and
2130 // tertiary opcode.  Only the opcode sections which a particular
2131 // instruction needs for encoding need to be specified.
2132 encode %{
2133   // Build emit functions for each basic byte or larger field in the
2134   // intel encoding scheme (opcode, rm, sib, immediate), and call them
2135   // from C++ code in the enc_class source block.  Emit functions will
2136   // live in the main source block for now.  In future, we can
2137   // generalize this by adding a syntax that specifies the sizes of
2138   // fields in an order, so that the adlc can build the emit functions
2139   // automagically
2140 
2141   // Emit primary opcode
2142   enc_class OpcP
2143   %{
2144     emit_opcode(cbuf, $primary);
2145   %}
2146 
2147   // Emit secondary opcode
2148   enc_class OpcS
2149   %{
2150     emit_opcode(cbuf, $secondary);
2151   %}
2152 
2153   // Emit tertiary opcode
2154   enc_class OpcT
2155   %{
2156     emit_opcode(cbuf, $tertiary);
2157   %}
2158 
2159   // Emit opcode directly
2160   enc_class Opcode(immI d8)
2161   %{
2162     emit_opcode(cbuf, $d8$$constant);
2163   %}
2164 
2165   // Emit size prefix
2166   enc_class SizePrefix
2167   %{
2168     emit_opcode(cbuf, 0x66);
2169   %}
2170 
2171   enc_class reg(rRegI reg)
2172   %{
2173     emit_rm(cbuf, 0x3, 0, $reg$$reg & 7);
2174   %}
2175 
2176   enc_class reg_reg(rRegI dst, rRegI src)
2177   %{
2178     emit_rm(cbuf, 0x3, $dst$$reg & 7, $src$$reg & 7);
2179   %}
2180 
2181   enc_class opc_reg_reg(immI opcode, rRegI dst, rRegI src)
2182   %{
2183     emit_opcode(cbuf, $opcode$$constant);
2184     emit_rm(cbuf, 0x3, $dst$$reg & 7, $src$$reg & 7);
2185   %}
2186 
2187   enc_class cmpfp_fixup() %{
2188       MacroAssembler _masm(&cbuf);
2189       emit_cmpfp_fixup(_masm);
2190   %}
2191 
2192   enc_class cmpfp3(rRegI dst)
2193   %{
2194     int dstenc = $dst$$reg;
2195 
2196     // movl $dst, -1
2197     if (dstenc >= 8) {
2198       emit_opcode(cbuf, Assembler::REX_B);
2199     }
2200     emit_opcode(cbuf, 0xB8 | (dstenc & 7));
2201     emit_d32(cbuf, -1);
2202 
2203     // jp,s done
2204     emit_opcode(cbuf, 0x7A);
2205     emit_d8(cbuf, dstenc < 4 ? 0x08 : 0x0A);
2206 
2207     // jb,s done
2208     emit_opcode(cbuf, 0x72);
2209     emit_d8(cbuf, dstenc < 4 ? 0x06 : 0x08);
2210 
2211     // setne $dst
2212     if (dstenc >= 4) {
2213       emit_opcode(cbuf, dstenc < 8 ? Assembler::REX : Assembler::REX_B);
2214     }
2215     emit_opcode(cbuf, 0x0F);
2216     emit_opcode(cbuf, 0x95);
2217     emit_opcode(cbuf, 0xC0 | (dstenc & 7));
2218 
2219     // movzbl $dst, $dst
2220     if (dstenc >= 4) {
2221       emit_opcode(cbuf, dstenc < 8 ? Assembler::REX : Assembler::REX_RB);
2222     }
2223     emit_opcode(cbuf, 0x0F);
2224     emit_opcode(cbuf, 0xB6);
2225     emit_rm(cbuf, 0x3, dstenc & 7, dstenc & 7);
2226   %}
2227 
2228   enc_class cdql_enc(no_rax_rdx_RegI div)
2229   %{
2230     // Full implementation of Java idiv and irem; checks for
2231     // special case as described in JVM spec., p.243 & p.271.
2232     //
2233     //         normal case                           special case
2234     //
2235     // input : rax: dividend                         min_int
2236     //         reg: divisor                          -1
2237     //
2238     // output: rax: quotient  (= rax idiv reg)       min_int
2239     //         rdx: remainder (= rax irem reg)       0
2240     //
2241     //  Code sequnce:
2242     //
2243     //    0:   3d 00 00 00 80          cmp    $0x80000000,%eax
2244     //    5:   75 07/08                jne    e <normal>
2245     //    7:   33 d2                   xor    %edx,%edx
2246     //  [div >= 8 -> offset + 1]
2247     //  [REX_B]
2248     //    9:   83 f9 ff                cmp    $0xffffffffffffffff,$div
2249     //    c:   74 03/04                je     11 <done>
2250     // 000000000000000e <normal>:
2251     //    e:   99                      cltd
2252     //  [div >= 8 -> offset + 1]
2253     //  [REX_B]
2254     //    f:   f7 f9                   idiv   $div
2255     // 0000000000000011 <done>:
2256 
2257     // cmp    $0x80000000,%eax
2258     emit_opcode(cbuf, 0x3d);
2259     emit_d8(cbuf, 0x00);
2260     emit_d8(cbuf, 0x00);
2261     emit_d8(cbuf, 0x00);
2262     emit_d8(cbuf, 0x80);
2263 
2264     // jne    e <normal>
2265     emit_opcode(cbuf, 0x75);
2266     emit_d8(cbuf, $div$$reg < 8 ? 0x07 : 0x08);
2267 
2268     // xor    %edx,%edx
2269     emit_opcode(cbuf, 0x33);
2270     emit_d8(cbuf, 0xD2);
2271 
2272     // cmp    $0xffffffffffffffff,%ecx
2273     if ($div$$reg >= 8) {
2274       emit_opcode(cbuf, Assembler::REX_B);
2275     }
2276     emit_opcode(cbuf, 0x83);
2277     emit_rm(cbuf, 0x3, 0x7, $div$$reg & 7);
2278     emit_d8(cbuf, 0xFF);
2279 
2280     // je     11 <done>
2281     emit_opcode(cbuf, 0x74);
2282     emit_d8(cbuf, $div$$reg < 8 ? 0x03 : 0x04);
2283 
2284     // <normal>
2285     // cltd
2286     emit_opcode(cbuf, 0x99);
2287 
2288     // idivl (note: must be emitted by the user of this rule)
2289     // <done>
2290   %}
2291 
2292   enc_class cdqq_enc(no_rax_rdx_RegL div)
2293   %{
2294     // Full implementation of Java ldiv and lrem; checks for
2295     // special case as described in JVM spec., p.243 & p.271.
2296     //
2297     //         normal case                           special case
2298     //
2299     // input : rax: dividend                         min_long
2300     //         reg: divisor                          -1
2301     //
2302     // output: rax: quotient  (= rax idiv reg)       min_long
2303     //         rdx: remainder (= rax irem reg)       0
2304     //
2305     //  Code sequnce:
2306     //
2307     //    0:   48 ba 00 00 00 00 00    mov    $0x8000000000000000,%rdx
2308     //    7:   00 00 80
2309     //    a:   48 39 d0                cmp    %rdx,%rax
2310     //    d:   75 08                   jne    17 <normal>
2311     //    f:   33 d2                   xor    %edx,%edx
2312     //   11:   48 83 f9 ff             cmp    $0xffffffffffffffff,$div
2313     //   15:   74 05                   je     1c <done>
2314     // 0000000000000017 <normal>:
2315     //   17:   48 99                   cqto
2316     //   19:   48 f7 f9                idiv   $div
2317     // 000000000000001c <done>:
2318 
2319     // mov    $0x8000000000000000,%rdx
2320     emit_opcode(cbuf, Assembler::REX_W);
2321     emit_opcode(cbuf, 0xBA);
2322     emit_d8(cbuf, 0x00);
2323     emit_d8(cbuf, 0x00);
2324     emit_d8(cbuf, 0x00);
2325     emit_d8(cbuf, 0x00);
2326     emit_d8(cbuf, 0x00);
2327     emit_d8(cbuf, 0x00);
2328     emit_d8(cbuf, 0x00);
2329     emit_d8(cbuf, 0x80);
2330 
2331     // cmp    %rdx,%rax
2332     emit_opcode(cbuf, Assembler::REX_W);
2333     emit_opcode(cbuf, 0x39);
2334     emit_d8(cbuf, 0xD0);
2335 
2336     // jne    17 <normal>
2337     emit_opcode(cbuf, 0x75);
2338     emit_d8(cbuf, 0x08);
2339 
2340     // xor    %edx,%edx
2341     emit_opcode(cbuf, 0x33);
2342     emit_d8(cbuf, 0xD2);
2343 
2344     // cmp    $0xffffffffffffffff,$div
2345     emit_opcode(cbuf, $div$$reg < 8 ? Assembler::REX_W : Assembler::REX_WB);
2346     emit_opcode(cbuf, 0x83);
2347     emit_rm(cbuf, 0x3, 0x7, $div$$reg & 7);
2348     emit_d8(cbuf, 0xFF);
2349 
2350     // je     1e <done>
2351     emit_opcode(cbuf, 0x74);
2352     emit_d8(cbuf, 0x05);
2353 
2354     // <normal>
2355     // cqto
2356     emit_opcode(cbuf, Assembler::REX_W);
2357     emit_opcode(cbuf, 0x99);
2358 
2359     // idivq (note: must be emitted by the user of this rule)
2360     // <done>
2361   %}
2362 
2363   // Opcde enc_class for 8/32 bit immediate instructions with sign-extension
2364   enc_class OpcSE(immI imm)
2365   %{
2366     // Emit primary opcode and set sign-extend bit
2367     // Check for 8-bit immediate, and set sign extend bit in opcode
2368     if (-0x80 <= $imm$$constant && $imm$$constant < 0x80) {
2369       emit_opcode(cbuf, $primary | 0x02);
2370     } else {
2371       // 32-bit immediate
2372       emit_opcode(cbuf, $primary);
2373     }
2374   %}
2375 
2376   enc_class OpcSErm(rRegI dst, immI imm)
2377   %{
2378     // OpcSEr/m
2379     int dstenc = $dst$$reg;
2380     if (dstenc >= 8) {
2381       emit_opcode(cbuf, Assembler::REX_B);
2382       dstenc -= 8;
2383     }
2384     // Emit primary opcode and set sign-extend bit
2385     // Check for 8-bit immediate, and set sign extend bit in opcode
2386     if (-0x80 <= $imm$$constant && $imm$$constant < 0x80) {
2387       emit_opcode(cbuf, $primary | 0x02);
2388     } else {
2389       // 32-bit immediate
2390       emit_opcode(cbuf, $primary);
2391     }
2392     // Emit r/m byte with secondary opcode, after primary opcode.
2393     emit_rm(cbuf, 0x3, $secondary, dstenc);
2394   %}
2395 
2396   enc_class OpcSErm_wide(rRegL dst, immI imm)
2397   %{
2398     // OpcSEr/m
2399     int dstenc = $dst$$reg;
2400     if (dstenc < 8) {
2401       emit_opcode(cbuf, Assembler::REX_W);
2402     } else {
2403       emit_opcode(cbuf, Assembler::REX_WB);
2404       dstenc -= 8;
2405     }
2406     // Emit primary opcode and set sign-extend bit
2407     // Check for 8-bit immediate, and set sign extend bit in opcode
2408     if (-0x80 <= $imm$$constant && $imm$$constant < 0x80) {
2409       emit_opcode(cbuf, $primary | 0x02);
2410     } else {
2411       // 32-bit immediate
2412       emit_opcode(cbuf, $primary);
2413     }
2414     // Emit r/m byte with secondary opcode, after primary opcode.
2415     emit_rm(cbuf, 0x3, $secondary, dstenc);
2416   %}
2417 
2418   enc_class Con8or32(immI imm)
2419   %{
2420     // Check for 8-bit immediate, and set sign extend bit in opcode
2421     if (-0x80 <= $imm$$constant && $imm$$constant < 0x80) {
2422       $$$emit8$imm$$constant;
2423     } else {
2424       // 32-bit immediate
2425       $$$emit32$imm$$constant;
2426     }
2427   %}
2428 
2429   enc_class Lbl(label labl)
2430   %{
2431     // GOTO
2432     Label* l = $labl$$label;
2433     emit_d32(cbuf, (l->loc_pos() - (cbuf.insts_size() + 4)));
2434   %}
2435 
2436   enc_class LblShort(label labl)
2437   %{
2438     // GOTO
2439     Label* l = $labl$$label;
2440     int disp = l->loc_pos() - (cbuf.insts_size() + 1);
2441     assert(-128 <= disp && disp <= 127, "Displacement too large for short jmp");
2442     emit_d8(cbuf, disp);
2443   %}
2444 
2445   enc_class opc2_reg(rRegI dst)
2446   %{
2447     // BSWAP
2448     emit_cc(cbuf, $secondary, $dst$$reg);
2449   %}
2450 
2451   enc_class opc3_reg(rRegI dst)
2452   %{
2453     // BSWAP
2454     emit_cc(cbuf, $tertiary, $dst$$reg);
2455   %}
2456 
2457   enc_class reg_opc(rRegI div)
2458   %{
2459     // INC, DEC, IDIV, IMOD, JMP indirect, ...
2460     emit_rm(cbuf, 0x3, $secondary, $div$$reg & 7);
2461   %}
2462 
2463   enc_class Jcc(cmpOp cop, label labl)
2464   %{
2465     // JCC
2466     Label* l = $labl$$label;
2467     $$$emit8$primary;
2468     emit_cc(cbuf, $secondary, $cop$$cmpcode);
2469     emit_d32(cbuf, (l->loc_pos() - (cbuf.insts_size() + 4)));
2470   %}
2471 
2472   enc_class JccShort (cmpOp cop, label labl)
2473   %{
2474   // JCC
2475     Label *l = $labl$$label;
2476     emit_cc(cbuf, $primary, $cop$$cmpcode);
2477     int disp = l->loc_pos() - (cbuf.insts_size() + 1);
2478     assert(-128 <= disp && disp <= 127, "Displacement too large for short jmp");
2479     emit_d8(cbuf, disp);
2480   %}
2481 
2482   enc_class enc_cmov(cmpOp cop)
2483   %{
2484     // CMOV
2485     $$$emit8$primary;
2486     emit_cc(cbuf, $secondary, $cop$$cmpcode);
2487   %}
2488 
2489   enc_class enc_cmovf_branch(cmpOp cop, regF dst, regF src)
2490   %{
2491     // Invert sense of branch from sense of cmov
2492     emit_cc(cbuf, 0x70, $cop$$cmpcode ^ 1);
2493     emit_d8(cbuf, ($dst$$reg < 8 && $src$$reg < 8)
2494                   ? (UseXmmRegToRegMoveAll ? 3 : 4)
2495                   : (UseXmmRegToRegMoveAll ? 4 : 5) ); // REX
2496     // UseXmmRegToRegMoveAll ? movaps(dst, src) : movss(dst, src)
2497     if (!UseXmmRegToRegMoveAll) emit_opcode(cbuf, 0xF3);
2498     if ($dst$$reg < 8) {
2499       if ($src$$reg >= 8) {
2500         emit_opcode(cbuf, Assembler::REX_B);
2501       }
2502     } else {
2503       if ($src$$reg < 8) {
2504         emit_opcode(cbuf, Assembler::REX_R);
2505       } else {
2506         emit_opcode(cbuf, Assembler::REX_RB);
2507       }
2508     }
2509     emit_opcode(cbuf, 0x0F);
2510     emit_opcode(cbuf, UseXmmRegToRegMoveAll ? 0x28 : 0x10);
2511     emit_rm(cbuf, 0x3, $dst$$reg & 7, $src$$reg & 7);
2512   %}
2513 
2514   enc_class enc_cmovd_branch(cmpOp cop, regD dst, regD src)
2515   %{
2516     // Invert sense of branch from sense of cmov
2517     emit_cc(cbuf, 0x70, $cop$$cmpcode ^ 1);
2518     emit_d8(cbuf, $dst$$reg < 8 && $src$$reg < 8 ? 4 : 5); // REX
2519 
2520     //  UseXmmRegToRegMoveAll ? movapd(dst, src) : movsd(dst, src)
2521     emit_opcode(cbuf, UseXmmRegToRegMoveAll ? 0x66 : 0xF2);
2522     if ($dst$$reg < 8) {
2523       if ($src$$reg >= 8) {
2524         emit_opcode(cbuf, Assembler::REX_B);
2525       }
2526     } else {
2527       if ($src$$reg < 8) {
2528         emit_opcode(cbuf, Assembler::REX_R);
2529       } else {
2530         emit_opcode(cbuf, Assembler::REX_RB);
2531       }
2532     }
2533     emit_opcode(cbuf, 0x0F);
2534     emit_opcode(cbuf, UseXmmRegToRegMoveAll ? 0x28 : 0x10);
2535     emit_rm(cbuf, 0x3, $dst$$reg & 7, $src$$reg & 7);
2536   %}
2537 
2538   enc_class enc_PartialSubtypeCheck()
2539   %{
2540     Register Rrdi = as_Register(RDI_enc); // result register
2541     Register Rrax = as_Register(RAX_enc); // super class
2542     Register Rrcx = as_Register(RCX_enc); // killed
2543     Register Rrsi = as_Register(RSI_enc); // sub class
2544     Label miss;
2545     const bool set_cond_codes = true;
2546 
2547     MacroAssembler _masm(&cbuf);
2548     __ check_klass_subtype_slow_path(Rrsi, Rrax, Rrcx, Rrdi,
2549                                      NULL, &miss,
2550                                      /*set_cond_codes:*/ true);
2551     if ($primary) {
2552       __ xorptr(Rrdi, Rrdi);
2553     }
2554     __ bind(miss);
2555   %}
2556 
2557   enc_class Java_To_Interpreter(method meth)
2558   %{
2559     // CALL Java_To_Interpreter
2560     // This is the instruction starting address for relocation info.
2561     cbuf.set_insts_mark();
2562     $$$emit8$primary;
2563     // CALL directly to the runtime
2564     emit_d32_reloc(cbuf,
2565                    (int) ($meth$$method - ((intptr_t) cbuf.insts_end()) - 4),
2566                    runtime_call_Relocation::spec(),
2567                    RELOC_DISP32);
2568   %}
2569 
2570   enc_class preserve_SP %{
2571     debug_only(int off0 = cbuf.insts_size());
2572     MacroAssembler _masm(&cbuf);
2573     // RBP is preserved across all calls, even compiled calls.
2574     // Use it to preserve RSP in places where the callee might change the SP.
2575     __ movptr(rbp_mh_SP_save, rsp);
2576     debug_only(int off1 = cbuf.insts_size());
2577     assert(off1 - off0 == preserve_SP_size(), "correct size prediction");
2578   %}
2579 
2580   enc_class restore_SP %{
2581     MacroAssembler _masm(&cbuf);
2582     __ movptr(rsp, rbp_mh_SP_save);
2583   %}
2584 
2585   enc_class Java_Static_Call(method meth)
2586   %{
2587     // JAVA STATIC CALL
2588     // CALL to fixup routine.  Fixup routine uses ScopeDesc info to
2589     // determine who we intended to call.
2590     cbuf.set_insts_mark();
2591     $$$emit8$primary;
2592 
2593     if (!_method) {
2594       emit_d32_reloc(cbuf,
2595                      (int) ($meth$$method - ((intptr_t) cbuf.insts_end()) - 4),
2596                      runtime_call_Relocation::spec(),
2597                      RELOC_DISP32);
2598     } else if (_optimized_virtual) {
2599       emit_d32_reloc(cbuf,
2600                      (int) ($meth$$method - ((intptr_t) cbuf.insts_end()) - 4),
2601                      opt_virtual_call_Relocation::spec(),
2602                      RELOC_DISP32);
2603     } else {
2604       emit_d32_reloc(cbuf,
2605                      (int) ($meth$$method - ((intptr_t) cbuf.insts_end()) - 4),
2606                      static_call_Relocation::spec(),
2607                      RELOC_DISP32);
2608     }
2609     if (_method) {
2610       // Emit stub for static call
2611       emit_java_to_interp(cbuf);
2612     }
2613   %}
2614 
2615   enc_class Java_Dynamic_Call(method meth)
2616   %{
2617     // JAVA DYNAMIC CALL
2618     // !!!!!
2619     // Generate  "movq rax, -1", placeholder instruction to load oop-info
2620     // emit_call_dynamic_prologue( cbuf );
2621     cbuf.set_insts_mark();
2622 
2623     // movq rax, -1
2624     emit_opcode(cbuf, Assembler::REX_W);
2625     emit_opcode(cbuf, 0xB8 | RAX_enc);
2626     emit_d64_reloc(cbuf,
2627                    (int64_t) Universe::non_oop_word(),
2628                    oop_Relocation::spec_for_immediate(), RELOC_IMM64);
2629     address virtual_call_oop_addr = cbuf.insts_mark();
2630     // CALL to fixup routine.  Fixup routine uses ScopeDesc info to determine
2631     // who we intended to call.
2632     cbuf.set_insts_mark();
2633     $$$emit8$primary;
2634     emit_d32_reloc(cbuf,
2635                    (int) ($meth$$method - ((intptr_t) cbuf.insts_end()) - 4),
2636                    virtual_call_Relocation::spec(virtual_call_oop_addr),
2637                    RELOC_DISP32);
2638   %}
2639 
2640   enc_class Java_Compiled_Call(method meth)
2641   %{
2642     // JAVA COMPILED CALL
2643     int disp = in_bytes(methodOopDesc:: from_compiled_offset());
2644 
2645     // XXX XXX offset is 128 is 1.5 NON-PRODUCT !!!
2646     // assert(-0x80 <= disp && disp < 0x80, "compiled_code_offset isn't small");
2647 
2648     // callq *disp(%rax)
2649     cbuf.set_insts_mark();
2650     $$$emit8$primary;
2651     if (disp < 0x80) {
2652       emit_rm(cbuf, 0x01, $secondary, RAX_enc); // R/M byte
2653       emit_d8(cbuf, disp); // Displacement
2654     } else {
2655       emit_rm(cbuf, 0x02, $secondary, RAX_enc); // R/M byte
2656       emit_d32(cbuf, disp); // Displacement
2657     }
2658   %}
2659 
2660   enc_class reg_opc_imm(rRegI dst, immI8 shift)
2661   %{
2662     // SAL, SAR, SHR
2663     int dstenc = $dst$$reg;
2664     if (dstenc >= 8) {
2665       emit_opcode(cbuf, Assembler::REX_B);
2666       dstenc -= 8;
2667     }
2668     $$$emit8$primary;
2669     emit_rm(cbuf, 0x3, $secondary, dstenc);
2670     $$$emit8$shift$$constant;
2671   %}
2672 
2673   enc_class reg_opc_imm_wide(rRegL dst, immI8 shift)
2674   %{
2675     // SAL, SAR, SHR
2676     int dstenc = $dst$$reg;
2677     if (dstenc < 8) {
2678       emit_opcode(cbuf, Assembler::REX_W);
2679     } else {
2680       emit_opcode(cbuf, Assembler::REX_WB);
2681       dstenc -= 8;
2682     }
2683     $$$emit8$primary;
2684     emit_rm(cbuf, 0x3, $secondary, dstenc);
2685     $$$emit8$shift$$constant;
2686   %}
2687 
2688   enc_class load_immI(rRegI dst, immI src)
2689   %{
2690     int dstenc = $dst$$reg;
2691     if (dstenc >= 8) {
2692       emit_opcode(cbuf, Assembler::REX_B);
2693       dstenc -= 8;
2694     }
2695     emit_opcode(cbuf, 0xB8 | dstenc);
2696     $$$emit32$src$$constant;
2697   %}
2698 
2699   enc_class load_immL(rRegL dst, immL src)
2700   %{
2701     int dstenc = $dst$$reg;
2702     if (dstenc < 8) {
2703       emit_opcode(cbuf, Assembler::REX_W);
2704     } else {
2705       emit_opcode(cbuf, Assembler::REX_WB);
2706       dstenc -= 8;
2707     }
2708     emit_opcode(cbuf, 0xB8 | dstenc);
2709     emit_d64(cbuf, $src$$constant);
2710   %}
2711 
2712   enc_class load_immUL32(rRegL dst, immUL32 src)
2713   %{
2714     // same as load_immI, but this time we care about zeroes in the high word
2715     int dstenc = $dst$$reg;
2716     if (dstenc >= 8) {
2717       emit_opcode(cbuf, Assembler::REX_B);
2718       dstenc -= 8;
2719     }
2720     emit_opcode(cbuf, 0xB8 | dstenc);
2721     $$$emit32$src$$constant;
2722   %}
2723 
2724   enc_class load_immL32(rRegL dst, immL32 src)
2725   %{
2726     int dstenc = $dst$$reg;
2727     if (dstenc < 8) {
2728       emit_opcode(cbuf, Assembler::REX_W);
2729     } else {
2730       emit_opcode(cbuf, Assembler::REX_WB);
2731       dstenc -= 8;
2732     }
2733     emit_opcode(cbuf, 0xC7);
2734     emit_rm(cbuf, 0x03, 0x00, dstenc);
2735     $$$emit32$src$$constant;
2736   %}
2737 
2738   enc_class load_immP31(rRegP dst, immP32 src)
2739   %{
2740     // same as load_immI, but this time we care about zeroes in the high word
2741     int dstenc = $dst$$reg;
2742     if (dstenc >= 8) {
2743       emit_opcode(cbuf, Assembler::REX_B);
2744       dstenc -= 8;
2745     }
2746     emit_opcode(cbuf, 0xB8 | dstenc);
2747     $$$emit32$src$$constant;
2748   %}
2749 
2750   enc_class load_immP(rRegP dst, immP src)
2751   %{
2752     int dstenc = $dst$$reg;
2753     if (dstenc < 8) {
2754       emit_opcode(cbuf, Assembler::REX_W);
2755     } else {
2756       emit_opcode(cbuf, Assembler::REX_WB);
2757       dstenc -= 8;
2758     }
2759     emit_opcode(cbuf, 0xB8 | dstenc);
2760     // This next line should be generated from ADLC
2761     if ($src->constant_is_oop()) {
2762       emit_d64_reloc(cbuf, $src$$constant, relocInfo::oop_type, RELOC_IMM64);
2763     } else {
2764       emit_d64(cbuf, $src$$constant);
2765     }
2766   %}
2767 
2768   // Encode a reg-reg copy.  If it is useless, then empty encoding.
2769   enc_class enc_copy(rRegI dst, rRegI src)
2770   %{
2771     encode_copy(cbuf, $dst$$reg, $src$$reg);
2772   %}
2773 
2774   // Encode xmm reg-reg copy.  If it is useless, then empty encoding.
2775   enc_class enc_CopyXD( RegD dst, RegD src ) %{
2776     encode_CopyXD( cbuf, $dst$$reg, $src$$reg );
2777   %}
2778 
2779   enc_class enc_copy_always(rRegI dst, rRegI src)
2780   %{
2781     int srcenc = $src$$reg;
2782     int dstenc = $dst$$reg;
2783 
2784     if (dstenc < 8) {
2785       if (srcenc >= 8) {
2786         emit_opcode(cbuf, Assembler::REX_B);
2787         srcenc -= 8;
2788       }
2789     } else {
2790       if (srcenc < 8) {
2791         emit_opcode(cbuf, Assembler::REX_R);
2792       } else {
2793         emit_opcode(cbuf, Assembler::REX_RB);
2794         srcenc -= 8;
2795       }
2796       dstenc -= 8;
2797     }
2798 
2799     emit_opcode(cbuf, 0x8B);
2800     emit_rm(cbuf, 0x3, dstenc, srcenc);
2801   %}
2802 
2803   enc_class enc_copy_wide(rRegL dst, rRegL src)
2804   %{
2805     int srcenc = $src$$reg;
2806     int dstenc = $dst$$reg;
2807 
2808     if (dstenc != srcenc) {
2809       if (dstenc < 8) {
2810         if (srcenc < 8) {
2811           emit_opcode(cbuf, Assembler::REX_W);
2812         } else {
2813           emit_opcode(cbuf, Assembler::REX_WB);
2814           srcenc -= 8;
2815         }
2816       } else {
2817         if (srcenc < 8) {
2818           emit_opcode(cbuf, Assembler::REX_WR);
2819         } else {
2820           emit_opcode(cbuf, Assembler::REX_WRB);
2821           srcenc -= 8;
2822         }
2823         dstenc -= 8;
2824       }
2825       emit_opcode(cbuf, 0x8B);
2826       emit_rm(cbuf, 0x3, dstenc, srcenc);
2827     }
2828   %}
2829 
2830   enc_class Con32(immI src)
2831   %{
2832     // Output immediate
2833     $$$emit32$src$$constant;
2834   %}
2835 
2836   enc_class Con64(immL src)
2837   %{
2838     // Output immediate
2839     emit_d64($src$$constant);
2840   %}
2841 
2842   enc_class Con32F_as_bits(immF src)
2843   %{
2844     // Output Float immediate bits
2845     jfloat jf = $src$$constant;
2846     jint jf_as_bits = jint_cast(jf);
2847     emit_d32(cbuf, jf_as_bits);
2848   %}
2849 
2850   enc_class Con16(immI src)
2851   %{
2852     // Output immediate
2853     $$$emit16$src$$constant;
2854   %}
2855 
2856   // How is this different from Con32??? XXX
2857   enc_class Con_d32(immI src)
2858   %{
2859     emit_d32(cbuf,$src$$constant);
2860   %}
2861 
2862   enc_class conmemref (rRegP t1) %{    // Con32(storeImmI)
2863     // Output immediate memory reference
2864     emit_rm(cbuf, 0x00, $t1$$reg, 0x05 );
2865     emit_d32(cbuf, 0x00);
2866   %}
2867 
2868   enc_class lock_prefix()
2869   %{
2870     if (os::is_MP()) {
2871       emit_opcode(cbuf, 0xF0); // lock
2872     }
2873   %}
2874 
2875   enc_class REX_mem(memory mem)
2876   %{
2877     if ($mem$$base >= 8) {
2878       if ($mem$$index < 8) {
2879         emit_opcode(cbuf, Assembler::REX_B);
2880       } else {
2881         emit_opcode(cbuf, Assembler::REX_XB);
2882       }
2883     } else {
2884       if ($mem$$index >= 8) {
2885         emit_opcode(cbuf, Assembler::REX_X);
2886       }
2887     }
2888   %}
2889 
2890   enc_class REX_mem_wide(memory mem)
2891   %{
2892     if ($mem$$base >= 8) {
2893       if ($mem$$index < 8) {
2894         emit_opcode(cbuf, Assembler::REX_WB);
2895       } else {
2896         emit_opcode(cbuf, Assembler::REX_WXB);
2897       }
2898     } else {
2899       if ($mem$$index < 8) {
2900         emit_opcode(cbuf, Assembler::REX_W);
2901       } else {
2902         emit_opcode(cbuf, Assembler::REX_WX);
2903       }
2904     }
2905   %}
2906 
2907   // for byte regs
2908   enc_class REX_breg(rRegI reg)
2909   %{
2910     if ($reg$$reg >= 4) {
2911       emit_opcode(cbuf, $reg$$reg < 8 ? Assembler::REX : Assembler::REX_B);
2912     }
2913   %}
2914 
2915   // for byte regs
2916   enc_class REX_reg_breg(rRegI dst, rRegI src)
2917   %{
2918     if ($dst$$reg < 8) {
2919       if ($src$$reg >= 4) {
2920         emit_opcode(cbuf, $src$$reg < 8 ? Assembler::REX : Assembler::REX_B);
2921       }
2922     } else {
2923       if ($src$$reg < 8) {
2924         emit_opcode(cbuf, Assembler::REX_R);
2925       } else {
2926         emit_opcode(cbuf, Assembler::REX_RB);
2927       }
2928     }
2929   %}
2930 
2931   // for byte regs
2932   enc_class REX_breg_mem(rRegI reg, memory mem)
2933   %{
2934     if ($reg$$reg < 8) {
2935       if ($mem$$base < 8) {
2936         if ($mem$$index >= 8) {
2937           emit_opcode(cbuf, Assembler::REX_X);
2938         } else if ($reg$$reg >= 4) {
2939           emit_opcode(cbuf, Assembler::REX);
2940         }
2941       } else {
2942         if ($mem$$index < 8) {
2943           emit_opcode(cbuf, Assembler::REX_B);
2944         } else {
2945           emit_opcode(cbuf, Assembler::REX_XB);
2946         }
2947       }
2948     } else {
2949       if ($mem$$base < 8) {
2950         if ($mem$$index < 8) {
2951           emit_opcode(cbuf, Assembler::REX_R);
2952         } else {
2953           emit_opcode(cbuf, Assembler::REX_RX);
2954         }
2955       } else {
2956         if ($mem$$index < 8) {
2957           emit_opcode(cbuf, Assembler::REX_RB);
2958         } else {
2959           emit_opcode(cbuf, Assembler::REX_RXB);
2960         }
2961       }
2962     }
2963   %}
2964 
2965   enc_class REX_reg(rRegI reg)
2966   %{
2967     if ($reg$$reg >= 8) {
2968       emit_opcode(cbuf, Assembler::REX_B);
2969     }
2970   %}
2971 
2972   enc_class REX_reg_wide(rRegI reg)
2973   %{
2974     if ($reg$$reg < 8) {
2975       emit_opcode(cbuf, Assembler::REX_W);
2976     } else {
2977       emit_opcode(cbuf, Assembler::REX_WB);
2978     }
2979   %}
2980 
2981   enc_class REX_reg_reg(rRegI dst, rRegI src)
2982   %{
2983     if ($dst$$reg < 8) {
2984       if ($src$$reg >= 8) {
2985         emit_opcode(cbuf, Assembler::REX_B);
2986       }
2987     } else {
2988       if ($src$$reg < 8) {
2989         emit_opcode(cbuf, Assembler::REX_R);
2990       } else {
2991         emit_opcode(cbuf, Assembler::REX_RB);
2992       }
2993     }
2994   %}
2995 
2996   enc_class REX_reg_reg_wide(rRegI dst, rRegI src)
2997   %{
2998     if ($dst$$reg < 8) {
2999       if ($src$$reg < 8) {
3000         emit_opcode(cbuf, Assembler::REX_W);
3001       } else {
3002         emit_opcode(cbuf, Assembler::REX_WB);
3003       }
3004     } else {
3005       if ($src$$reg < 8) {
3006         emit_opcode(cbuf, Assembler::REX_WR);
3007       } else {
3008         emit_opcode(cbuf, Assembler::REX_WRB);
3009       }
3010     }
3011   %}
3012 
3013   enc_class REX_reg_mem(rRegI reg, memory mem)
3014   %{
3015     if ($reg$$reg < 8) {
3016       if ($mem$$base < 8) {
3017         if ($mem$$index >= 8) {
3018           emit_opcode(cbuf, Assembler::REX_X);
3019         }
3020       } else {
3021         if ($mem$$index < 8) {
3022           emit_opcode(cbuf, Assembler::REX_B);
3023         } else {
3024           emit_opcode(cbuf, Assembler::REX_XB);
3025         }
3026       }
3027     } else {
3028       if ($mem$$base < 8) {
3029         if ($mem$$index < 8) {
3030           emit_opcode(cbuf, Assembler::REX_R);
3031         } else {
3032           emit_opcode(cbuf, Assembler::REX_RX);
3033         }
3034       } else {
3035         if ($mem$$index < 8) {
3036           emit_opcode(cbuf, Assembler::REX_RB);
3037         } else {
3038           emit_opcode(cbuf, Assembler::REX_RXB);
3039         }
3040       }
3041     }
3042   %}
3043 
3044   enc_class REX_reg_mem_wide(rRegL reg, memory mem)
3045   %{
3046     if ($reg$$reg < 8) {
3047       if ($mem$$base < 8) {
3048         if ($mem$$index < 8) {
3049           emit_opcode(cbuf, Assembler::REX_W);
3050         } else {
3051           emit_opcode(cbuf, Assembler::REX_WX);
3052         }
3053       } else {
3054         if ($mem$$index < 8) {
3055           emit_opcode(cbuf, Assembler::REX_WB);
3056         } else {
3057           emit_opcode(cbuf, Assembler::REX_WXB);
3058         }
3059       }
3060     } else {
3061       if ($mem$$base < 8) {
3062         if ($mem$$index < 8) {
3063           emit_opcode(cbuf, Assembler::REX_WR);
3064         } else {
3065           emit_opcode(cbuf, Assembler::REX_WRX);
3066         }
3067       } else {
3068         if ($mem$$index < 8) {
3069           emit_opcode(cbuf, Assembler::REX_WRB);
3070         } else {
3071           emit_opcode(cbuf, Assembler::REX_WRXB);
3072         }
3073       }
3074     }
3075   %}
3076 
3077   enc_class reg_mem(rRegI ereg, memory mem)
3078   %{
3079     // High registers handle in encode_RegMem
3080     int reg = $ereg$$reg;
3081     int base = $mem$$base;
3082     int index = $mem$$index;
3083     int scale = $mem$$scale;
3084     int disp = $mem$$disp;
3085     bool disp_is_oop = $mem->disp_is_oop();
3086 
3087     encode_RegMem(cbuf, reg, base, index, scale, disp, disp_is_oop);
3088   %}
3089 
3090   enc_class RM_opc_mem(immI rm_opcode, memory mem)
3091   %{
3092     int rm_byte_opcode = $rm_opcode$$constant;
3093 
3094     // High registers handle in encode_RegMem
3095     int base = $mem$$base;
3096     int index = $mem$$index;
3097     int scale = $mem$$scale;
3098     int displace = $mem$$disp;
3099 
3100     bool disp_is_oop = $mem->disp_is_oop(); // disp-as-oop when
3101                                             // working with static
3102                                             // globals
3103     encode_RegMem(cbuf, rm_byte_opcode, base, index, scale, displace,
3104                   disp_is_oop);
3105   %}
3106 
3107   enc_class reg_lea(rRegI dst, rRegI src0, immI src1)
3108   %{
3109     int reg_encoding = $dst$$reg;
3110     int base         = $src0$$reg;      // 0xFFFFFFFF indicates no base
3111     int index        = 0x04;            // 0x04 indicates no index
3112     int scale        = 0x00;            // 0x00 indicates no scale
3113     int displace     = $src1$$constant; // 0x00 indicates no displacement
3114     bool disp_is_oop = false;
3115     encode_RegMem(cbuf, reg_encoding, base, index, scale, displace,
3116                   disp_is_oop);
3117   %}
3118 
3119   enc_class neg_reg(rRegI dst)
3120   %{
3121     int dstenc = $dst$$reg;
3122     if (dstenc >= 8) {
3123       emit_opcode(cbuf, Assembler::REX_B);
3124       dstenc -= 8;
3125     }
3126     // NEG $dst
3127     emit_opcode(cbuf, 0xF7);
3128     emit_rm(cbuf, 0x3, 0x03, dstenc);
3129   %}
3130 
3131   enc_class neg_reg_wide(rRegI dst)
3132   %{
3133     int dstenc = $dst$$reg;
3134     if (dstenc < 8) {
3135       emit_opcode(cbuf, Assembler::REX_W);
3136     } else {
3137       emit_opcode(cbuf, Assembler::REX_WB);
3138       dstenc -= 8;
3139     }
3140     // NEG $dst
3141     emit_opcode(cbuf, 0xF7);
3142     emit_rm(cbuf, 0x3, 0x03, dstenc);
3143   %}
3144 
3145   enc_class setLT_reg(rRegI dst)
3146   %{
3147     int dstenc = $dst$$reg;
3148     if (dstenc >= 8) {
3149       emit_opcode(cbuf, Assembler::REX_B);
3150       dstenc -= 8;
3151     } else if (dstenc >= 4) {
3152       emit_opcode(cbuf, Assembler::REX);
3153     }
3154     // SETLT $dst
3155     emit_opcode(cbuf, 0x0F);
3156     emit_opcode(cbuf, 0x9C);
3157     emit_rm(cbuf, 0x3, 0x0, dstenc);
3158   %}
3159 
3160   enc_class setNZ_reg(rRegI dst)
3161   %{
3162     int dstenc = $dst$$reg;
3163     if (dstenc >= 8) {
3164       emit_opcode(cbuf, Assembler::REX_B);
3165       dstenc -= 8;
3166     } else if (dstenc >= 4) {
3167       emit_opcode(cbuf, Assembler::REX);
3168     }
3169     // SETNZ $dst
3170     emit_opcode(cbuf, 0x0F);
3171     emit_opcode(cbuf, 0x95);
3172     emit_rm(cbuf, 0x3, 0x0, dstenc);
3173   %}
3174 
3175 
3176   // Compare the lonogs and set -1, 0, or 1 into dst
3177   enc_class cmpl3_flag(rRegL src1, rRegL src2, rRegI dst)
3178   %{
3179     int src1enc = $src1$$reg;
3180     int src2enc = $src2$$reg;
3181     int dstenc = $dst$$reg;
3182 
3183     // cmpq $src1, $src2
3184     if (src1enc < 8) {
3185       if (src2enc < 8) {
3186         emit_opcode(cbuf, Assembler::REX_W);
3187       } else {
3188         emit_opcode(cbuf, Assembler::REX_WB);
3189       }
3190     } else {
3191       if (src2enc < 8) {
3192         emit_opcode(cbuf, Assembler::REX_WR);
3193       } else {
3194         emit_opcode(cbuf, Assembler::REX_WRB);
3195       }
3196     }
3197     emit_opcode(cbuf, 0x3B);
3198     emit_rm(cbuf, 0x3, src1enc & 7, src2enc & 7);
3199 
3200     // movl $dst, -1
3201     if (dstenc >= 8) {
3202       emit_opcode(cbuf, Assembler::REX_B);
3203     }
3204     emit_opcode(cbuf, 0xB8 | (dstenc & 7));
3205     emit_d32(cbuf, -1);
3206 
3207     // jl,s done
3208     emit_opcode(cbuf, 0x7C);
3209     emit_d8(cbuf, dstenc < 4 ? 0x06 : 0x08);
3210 
3211     // setne $dst
3212     if (dstenc >= 4) {
3213       emit_opcode(cbuf, dstenc < 8 ? Assembler::REX : Assembler::REX_B);
3214     }
3215     emit_opcode(cbuf, 0x0F);
3216     emit_opcode(cbuf, 0x95);
3217     emit_opcode(cbuf, 0xC0 | (dstenc & 7));
3218 
3219     // movzbl $dst, $dst
3220     if (dstenc >= 4) {
3221       emit_opcode(cbuf, dstenc < 8 ? Assembler::REX : Assembler::REX_RB);
3222     }
3223     emit_opcode(cbuf, 0x0F);
3224     emit_opcode(cbuf, 0xB6);
3225     emit_rm(cbuf, 0x3, dstenc & 7, dstenc & 7);
3226   %}
3227 
3228   enc_class Push_ResultXD(regD dst) %{
3229     int dstenc = $dst$$reg;
3230 
3231     store_to_stackslot( cbuf, 0xDD, 0x03, 0 ); //FSTP [RSP]
3232 
3233     // UseXmmLoadAndClearUpper ? movsd dst,[rsp] : movlpd dst,[rsp]
3234     emit_opcode  (cbuf, UseXmmLoadAndClearUpper ? 0xF2 : 0x66);
3235     if (dstenc >= 8) {
3236       emit_opcode(cbuf, Assembler::REX_R);
3237     }
3238     emit_opcode  (cbuf, 0x0F );
3239     emit_opcode  (cbuf, UseXmmLoadAndClearUpper ? 0x10 : 0x12 );
3240     encode_RegMem(cbuf, dstenc, RSP_enc, 0x4, 0, 0, false);
3241 
3242     // add rsp,8
3243     emit_opcode(cbuf, Assembler::REX_W);
3244     emit_opcode(cbuf,0x83);
3245     emit_rm(cbuf,0x3, 0x0, RSP_enc);
3246     emit_d8(cbuf,0x08);
3247   %}
3248 
3249   enc_class Push_SrcXD(regD src) %{
3250     int srcenc = $src$$reg;
3251 
3252     // subq rsp,#8
3253     emit_opcode(cbuf, Assembler::REX_W);
3254     emit_opcode(cbuf, 0x83);
3255     emit_rm(cbuf, 0x3, 0x5, RSP_enc);
3256     emit_d8(cbuf, 0x8);
3257 
3258     // movsd [rsp],src
3259     emit_opcode(cbuf, 0xF2);
3260     if (srcenc >= 8) {
3261       emit_opcode(cbuf, Assembler::REX_R);
3262     }
3263     emit_opcode(cbuf, 0x0F);
3264     emit_opcode(cbuf, 0x11);
3265     encode_RegMem(cbuf, srcenc, RSP_enc, 0x4, 0, 0, false);
3266 
3267     // fldd [rsp]
3268     emit_opcode(cbuf, 0x66);
3269     emit_opcode(cbuf, 0xDD);
3270     encode_RegMem(cbuf, 0x0, RSP_enc, 0x4, 0, 0, false);
3271   %}
3272 
3273 
3274   enc_class movq_ld(regD dst, memory mem) %{
3275     MacroAssembler _masm(&cbuf);
3276     __ movq($dst$$XMMRegister, $mem$$Address);
3277   %}
3278 
3279   enc_class movq_st(memory mem, regD src) %{
3280     MacroAssembler _masm(&cbuf);
3281     __ movq($mem$$Address, $src$$XMMRegister);
3282   %}
3283 
3284   enc_class pshufd_8x8(regF dst, regF src) %{
3285     MacroAssembler _masm(&cbuf);
3286 
3287     encode_CopyXD(cbuf, $dst$$reg, $src$$reg);
3288     __ punpcklbw(as_XMMRegister($dst$$reg), as_XMMRegister($dst$$reg));
3289     __ pshuflw(as_XMMRegister($dst$$reg), as_XMMRegister($dst$$reg), 0x00);
3290   %}
3291 
3292   enc_class pshufd_4x16(regF dst, regF src) %{
3293     MacroAssembler _masm(&cbuf);
3294 
3295     __ pshuflw(as_XMMRegister($dst$$reg), as_XMMRegister($src$$reg), 0x00);
3296   %}
3297 
3298   enc_class pshufd(regD dst, regD src, int mode) %{
3299     MacroAssembler _masm(&cbuf);
3300 
3301     __ pshufd(as_XMMRegister($dst$$reg), as_XMMRegister($src$$reg), $mode);
3302   %}
3303 
3304   enc_class pxor(regD dst, regD src) %{
3305     MacroAssembler _masm(&cbuf);
3306 
3307     __ pxor(as_XMMRegister($dst$$reg), as_XMMRegister($src$$reg));
3308   %}
3309 
3310   enc_class mov_i2x(regD dst, rRegI src) %{
3311     MacroAssembler _masm(&cbuf);
3312 
3313     __ movdl(as_XMMRegister($dst$$reg), as_Register($src$$reg));
3314   %}
3315 
3316   // obj: object to lock
3317   // box: box address (header location) -- killed
3318   // tmp: rax -- killed
3319   // scr: rbx -- killed
3320   //
3321   // What follows is a direct transliteration of fast_lock() and fast_unlock()
3322   // from i486.ad.  See that file for comments.
3323   // TODO: where possible switch from movq (r, 0) to movl(r,0) and
3324   // use the shorter encoding.  (Movl clears the high-order 32-bits).
3325 
3326 
3327   enc_class Fast_Lock(rRegP obj, rRegP box, rax_RegI tmp, rRegP scr)
3328   %{
3329     Register objReg = as_Register((int)$obj$$reg);
3330     Register boxReg = as_Register((int)$box$$reg);
3331     Register tmpReg = as_Register($tmp$$reg);
3332     Register scrReg = as_Register($scr$$reg);
3333     MacroAssembler masm(&cbuf);
3334 
3335     // Verify uniqueness of register assignments -- necessary but not sufficient
3336     assert (objReg != boxReg && objReg != tmpReg &&
3337             objReg != scrReg && tmpReg != scrReg, "invariant") ;
3338 
3339     if (_counters != NULL) {
3340       masm.atomic_incl(ExternalAddress((address) _counters->total_entry_count_addr()));
3341     }
3342     if (EmitSync & 1) {
3343         // Without cast to int32_t a movptr will destroy r10 which is typically obj
3344         masm.movptr (Address(boxReg, 0), (int32_t)intptr_t(markOopDesc::unused_mark())) ;
3345         masm.cmpptr(rsp, (int32_t)NULL_WORD) ;
3346     } else
3347     if (EmitSync & 2) {
3348         Label DONE_LABEL;
3349         if (UseBiasedLocking) {
3350            // Note: tmpReg maps to the swap_reg argument and scrReg to the tmp_reg argument.
3351           masm.biased_locking_enter(boxReg, objReg, tmpReg, scrReg, false, DONE_LABEL, NULL, _counters);
3352         }
3353         // QQQ was movl...
3354         masm.movptr(tmpReg, 0x1);
3355         masm.orptr(tmpReg, Address(objReg, 0));
3356         masm.movptr(Address(boxReg, 0), tmpReg);
3357         if (os::is_MP()) {
3358           masm.lock();
3359         }
3360         masm.cmpxchgptr(boxReg, Address(objReg, 0)); // Updates tmpReg
3361         masm.jcc(Assembler::equal, DONE_LABEL);
3362 
3363         // Recursive locking
3364         masm.subptr(tmpReg, rsp);
3365         masm.andptr(tmpReg, 7 - os::vm_page_size());
3366         masm.movptr(Address(boxReg, 0), tmpReg);
3367 
3368         masm.bind(DONE_LABEL);
3369         masm.nop(); // avoid branch to branch
3370     } else {
3371         Label DONE_LABEL, IsInflated, Egress;
3372 
3373         masm.movptr(tmpReg, Address(objReg, 0)) ;
3374         masm.testl (tmpReg, 0x02) ;         // inflated vs stack-locked|neutral|biased
3375         masm.jcc   (Assembler::notZero, IsInflated) ;
3376 
3377         // it's stack-locked, biased or neutral
3378         // TODO: optimize markword triage order to reduce the number of
3379         // conditional branches in the most common cases.
3380         // Beware -- there's a subtle invariant that fetch of the markword
3381         // at [FETCH], below, will never observe a biased encoding (*101b).
3382         // If this invariant is not held we'll suffer exclusion (safety) failure.
3383 
3384         if (UseBiasedLocking && !UseOptoBiasInlining) {
3385           masm.biased_locking_enter(boxReg, objReg, tmpReg, scrReg, true, DONE_LABEL, NULL, _counters);
3386           masm.movptr(tmpReg, Address(objReg, 0)) ;        // [FETCH]
3387         }
3388 
3389         // was q will it destroy high?
3390         masm.orl   (tmpReg, 1) ;
3391         masm.movptr(Address(boxReg, 0), tmpReg) ;
3392         if (os::is_MP()) { masm.lock(); }
3393         masm.cmpxchgptr(boxReg, Address(objReg, 0)); // Updates tmpReg
3394         if (_counters != NULL) {
3395            masm.cond_inc32(Assembler::equal,
3396                            ExternalAddress((address) _counters->fast_path_entry_count_addr()));
3397         }
3398         masm.jcc   (Assembler::equal, DONE_LABEL);
3399 
3400         // Recursive locking
3401         masm.subptr(tmpReg, rsp);
3402         masm.andptr(tmpReg, 7 - os::vm_page_size());
3403         masm.movptr(Address(boxReg, 0), tmpReg);
3404         if (_counters != NULL) {
3405            masm.cond_inc32(Assembler::equal,
3406                            ExternalAddress((address) _counters->fast_path_entry_count_addr()));
3407         }
3408         masm.jmp   (DONE_LABEL) ;
3409 
3410         masm.bind  (IsInflated) ;
3411         // It's inflated
3412 
3413         // TODO: someday avoid the ST-before-CAS penalty by
3414         // relocating (deferring) the following ST.
3415         // We should also think about trying a CAS without having
3416         // fetched _owner.  If the CAS is successful we may
3417         // avoid an RTO->RTS upgrade on the $line.
3418         // Without cast to int32_t a movptr will destroy r10 which is typically obj
3419         masm.movptr(Address(boxReg, 0), (int32_t)intptr_t(markOopDesc::unused_mark())) ;
3420 
3421         masm.mov    (boxReg, tmpReg) ;
3422         masm.movptr (tmpReg, Address(tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ;
3423         masm.testptr(tmpReg, tmpReg) ;
3424         masm.jcc    (Assembler::notZero, DONE_LABEL) ;
3425 
3426         // It's inflated and appears unlocked
3427         if (os::is_MP()) { masm.lock(); }
3428         masm.cmpxchgptr(r15_thread, Address(boxReg, ObjectMonitor::owner_offset_in_bytes()-2)) ;
3429         // Intentional fall-through into DONE_LABEL ...
3430 
3431         masm.bind  (DONE_LABEL) ;
3432         masm.nop   () ;                 // avoid jmp to jmp
3433     }
3434   %}
3435 
3436   // obj: object to unlock
3437   // box: box address (displaced header location), killed
3438   // RBX: killed tmp; cannot be obj nor box
3439   enc_class Fast_Unlock(rRegP obj, rax_RegP box, rRegP tmp)
3440   %{
3441 
3442     Register objReg = as_Register($obj$$reg);
3443     Register boxReg = as_Register($box$$reg);
3444     Register tmpReg = as_Register($tmp$$reg);
3445     MacroAssembler masm(&cbuf);
3446 
3447     if (EmitSync & 4) {
3448        masm.cmpptr(rsp, 0) ;
3449     } else
3450     if (EmitSync & 8) {
3451        Label DONE_LABEL;
3452        if (UseBiasedLocking) {
3453          masm.biased_locking_exit(objReg, tmpReg, DONE_LABEL);
3454        }
3455 
3456        // Check whether the displaced header is 0
3457        //(=> recursive unlock)
3458        masm.movptr(tmpReg, Address(boxReg, 0));
3459        masm.testptr(tmpReg, tmpReg);
3460        masm.jcc(Assembler::zero, DONE_LABEL);
3461 
3462        // If not recursive lock, reset the header to displaced header
3463        if (os::is_MP()) {
3464          masm.lock();
3465        }
3466        masm.cmpxchgptr(tmpReg, Address(objReg, 0)); // Uses RAX which is box
3467        masm.bind(DONE_LABEL);
3468        masm.nop(); // avoid branch to branch
3469     } else {
3470        Label DONE_LABEL, Stacked, CheckSucc ;
3471 
3472        if (UseBiasedLocking && !UseOptoBiasInlining) {
3473          masm.biased_locking_exit(objReg, tmpReg, DONE_LABEL);
3474        }
3475 
3476        masm.movptr(tmpReg, Address(objReg, 0)) ;
3477        masm.cmpptr(Address(boxReg, 0), (int32_t)NULL_WORD) ;
3478        masm.jcc   (Assembler::zero, DONE_LABEL) ;
3479        masm.testl (tmpReg, 0x02) ;
3480        masm.jcc   (Assembler::zero, Stacked) ;
3481 
3482        // It's inflated
3483        masm.movptr(boxReg, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ;
3484        masm.xorptr(boxReg, r15_thread) ;
3485        masm.orptr (boxReg, Address (tmpReg, ObjectMonitor::recursions_offset_in_bytes()-2)) ;
3486        masm.jcc   (Assembler::notZero, DONE_LABEL) ;
3487        masm.movptr(boxReg, Address (tmpReg, ObjectMonitor::cxq_offset_in_bytes()-2)) ;
3488        masm.orptr (boxReg, Address (tmpReg, ObjectMonitor::EntryList_offset_in_bytes()-2)) ;
3489        masm.jcc   (Assembler::notZero, CheckSucc) ;
3490        masm.movptr(Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), (int32_t)NULL_WORD) ;
3491        masm.jmp   (DONE_LABEL) ;
3492 
3493        if ((EmitSync & 65536) == 0) {
3494          Label LSuccess, LGoSlowPath ;
3495          masm.bind  (CheckSucc) ;
3496          masm.cmpptr(Address (tmpReg, ObjectMonitor::succ_offset_in_bytes()-2), (int32_t)NULL_WORD) ;
3497          masm.jcc   (Assembler::zero, LGoSlowPath) ;
3498 
3499          // I'd much rather use lock:andl m->_owner, 0 as it's faster than the
3500          // the explicit ST;MEMBAR combination, but masm doesn't currently support
3501          // "ANDQ M,IMM".  Don't use MFENCE here.  lock:add to TOS, xchg, etc
3502          // are all faster when the write buffer is populated.
3503          masm.movptr (Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), (int32_t)NULL_WORD) ;
3504          if (os::is_MP()) {
3505             masm.lock () ; masm.addl (Address(rsp, 0), 0) ;
3506          }
3507          masm.cmpptr(Address (tmpReg, ObjectMonitor::succ_offset_in_bytes()-2), (int32_t)NULL_WORD) ;
3508          masm.jcc   (Assembler::notZero, LSuccess) ;
3509 
3510          masm.movptr (boxReg, (int32_t)NULL_WORD) ;                   // box is really EAX
3511          if (os::is_MP()) { masm.lock(); }
3512          masm.cmpxchgptr(r15_thread, Address(tmpReg, ObjectMonitor::owner_offset_in_bytes()-2));
3513          masm.jcc   (Assembler::notEqual, LSuccess) ;
3514          // Intentional fall-through into slow-path
3515 
3516          masm.bind  (LGoSlowPath) ;
3517          masm.orl   (boxReg, 1) ;                      // set ICC.ZF=0 to indicate failure
3518          masm.jmp   (DONE_LABEL) ;
3519 
3520          masm.bind  (LSuccess) ;
3521          masm.testl (boxReg, 0) ;                      // set ICC.ZF=1 to indicate success
3522          masm.jmp   (DONE_LABEL) ;
3523        }
3524 
3525        masm.bind  (Stacked) ;
3526        masm.movptr(tmpReg, Address (boxReg, 0)) ;      // re-fetch
3527        if (os::is_MP()) { masm.lock(); }
3528        masm.cmpxchgptr(tmpReg, Address(objReg, 0)); // Uses RAX which is box
3529 
3530        if (EmitSync & 65536) {
3531           masm.bind (CheckSucc) ;
3532        }
3533        masm.bind(DONE_LABEL);
3534        if (EmitSync & 32768) {
3535           masm.nop();                      // avoid branch to branch
3536        }
3537     }
3538   %}
3539 
3540 
3541   enc_class enc_rethrow()
3542   %{
3543     cbuf.set_insts_mark();
3544     emit_opcode(cbuf, 0xE9); // jmp entry
3545     emit_d32_reloc(cbuf,
3546                    (int) (OptoRuntime::rethrow_stub() - cbuf.insts_end() - 4),
3547                    runtime_call_Relocation::spec(),
3548                    RELOC_DISP32);
3549   %}
3550 
3551   enc_class absF_encoding(regF dst)
3552   %{
3553     int dstenc = $dst$$reg;
3554     address signmask_address = (address) StubRoutines::x86::float_sign_mask();
3555 
3556     cbuf.set_insts_mark();
3557     if (dstenc >= 8) {
3558       emit_opcode(cbuf, Assembler::REX_R);
3559       dstenc -= 8;
3560     }
3561     // XXX reg_mem doesn't support RIP-relative addressing yet
3562     emit_opcode(cbuf, 0x0F);
3563     emit_opcode(cbuf, 0x54);
3564     emit_rm(cbuf, 0x0, dstenc, 0x5);  // 00 reg 101
3565     emit_d32_reloc(cbuf, signmask_address);
3566   %}
3567 
3568   enc_class absD_encoding(regD dst)
3569   %{
3570     int dstenc = $dst$$reg;
3571     address signmask_address = (address) StubRoutines::x86::double_sign_mask();
3572 
3573     cbuf.set_insts_mark();
3574     emit_opcode(cbuf, 0x66);
3575     if (dstenc >= 8) {
3576       emit_opcode(cbuf, Assembler::REX_R);
3577       dstenc -= 8;
3578     }
3579     // XXX reg_mem doesn't support RIP-relative addressing yet
3580     emit_opcode(cbuf, 0x0F);
3581     emit_opcode(cbuf, 0x54);
3582     emit_rm(cbuf, 0x0, dstenc, 0x5);  // 00 reg 101
3583     emit_d32_reloc(cbuf, signmask_address);
3584   %}
3585 
3586   enc_class negF_encoding(regF dst)
3587   %{
3588     int dstenc = $dst$$reg;
3589     address signflip_address = (address) StubRoutines::x86::float_sign_flip();
3590 
3591     cbuf.set_insts_mark();
3592     if (dstenc >= 8) {
3593       emit_opcode(cbuf, Assembler::REX_R);
3594       dstenc -= 8;
3595     }
3596     // XXX reg_mem doesn't support RIP-relative addressing yet
3597     emit_opcode(cbuf, 0x0F);
3598     emit_opcode(cbuf, 0x57);
3599     emit_rm(cbuf, 0x0, dstenc, 0x5);  // 00 reg 101
3600     emit_d32_reloc(cbuf, signflip_address);
3601   %}
3602 
3603   enc_class negD_encoding(regD dst)
3604   %{
3605     int dstenc = $dst$$reg;
3606     address signflip_address = (address) StubRoutines::x86::double_sign_flip();
3607 
3608     cbuf.set_insts_mark();
3609     emit_opcode(cbuf, 0x66);
3610     if (dstenc >= 8) {
3611       emit_opcode(cbuf, Assembler::REX_R);
3612       dstenc -= 8;
3613     }
3614     // XXX reg_mem doesn't support RIP-relative addressing yet
3615     emit_opcode(cbuf, 0x0F);
3616     emit_opcode(cbuf, 0x57);
3617     emit_rm(cbuf, 0x0, dstenc, 0x5);  // 00 reg 101
3618     emit_d32_reloc(cbuf, signflip_address);
3619   %}
3620 
3621   enc_class f2i_fixup(rRegI dst, regF src)
3622   %{
3623     int dstenc = $dst$$reg;
3624     int srcenc = $src$$reg;
3625 
3626     // cmpl $dst, #0x80000000
3627     if (dstenc >= 8) {
3628       emit_opcode(cbuf, Assembler::REX_B);
3629     }
3630     emit_opcode(cbuf, 0x81);
3631     emit_rm(cbuf, 0x3, 0x7, dstenc & 7);
3632     emit_d32(cbuf, 0x80000000);
3633 
3634     // jne,s done
3635     emit_opcode(cbuf, 0x75);
3636     if (srcenc < 8 && dstenc < 8) {
3637       emit_d8(cbuf, 0xF);
3638     } else if (srcenc >= 8 && dstenc >= 8) {
3639       emit_d8(cbuf, 0x11);
3640     } else {
3641       emit_d8(cbuf, 0x10);
3642     }
3643 
3644     // subq rsp, #8
3645     emit_opcode(cbuf, Assembler::REX_W);
3646     emit_opcode(cbuf, 0x83);
3647     emit_rm(cbuf, 0x3, 0x5, RSP_enc);
3648     emit_d8(cbuf, 8);
3649 
3650     // movss [rsp], $src
3651     emit_opcode(cbuf, 0xF3);
3652     if (srcenc >= 8) {
3653       emit_opcode(cbuf, Assembler::REX_R);
3654     }
3655     emit_opcode(cbuf, 0x0F);
3656     emit_opcode(cbuf, 0x11);
3657     encode_RegMem(cbuf, srcenc, RSP_enc, 0x4, 0, 0, false); // 2 bytes
3658 
3659     // call f2i_fixup
3660     cbuf.set_insts_mark();
3661     emit_opcode(cbuf, 0xE8);
3662     emit_d32_reloc(cbuf,
3663                    (int)
3664                    (StubRoutines::x86::f2i_fixup() - cbuf.insts_end() - 4),
3665                    runtime_call_Relocation::spec(),
3666                    RELOC_DISP32);
3667 
3668     // popq $dst
3669     if (dstenc >= 8) {
3670       emit_opcode(cbuf, Assembler::REX_B);
3671     }
3672     emit_opcode(cbuf, 0x58 | (dstenc & 7));
3673 
3674     // done:
3675   %}
3676 
3677   enc_class f2l_fixup(rRegL dst, regF src)
3678   %{
3679     int dstenc = $dst$$reg;
3680     int srcenc = $src$$reg;
3681     address const_address = (address) StubRoutines::x86::double_sign_flip();
3682 
3683     // cmpq $dst, [0x8000000000000000]
3684     cbuf.set_insts_mark();
3685     emit_opcode(cbuf, dstenc < 8 ? Assembler::REX_W : Assembler::REX_WR);
3686     emit_opcode(cbuf, 0x39);
3687     // XXX reg_mem doesn't support RIP-relative addressing yet
3688     emit_rm(cbuf, 0x0, dstenc & 7, 0x5); // 00 reg 101
3689     emit_d32_reloc(cbuf, const_address);
3690 
3691 
3692     // jne,s done
3693     emit_opcode(cbuf, 0x75);
3694     if (srcenc < 8 && dstenc < 8) {
3695       emit_d8(cbuf, 0xF);
3696     } else if (srcenc >= 8 && dstenc >= 8) {
3697       emit_d8(cbuf, 0x11);
3698     } else {
3699       emit_d8(cbuf, 0x10);
3700     }
3701 
3702     // subq rsp, #8
3703     emit_opcode(cbuf, Assembler::REX_W);
3704     emit_opcode(cbuf, 0x83);
3705     emit_rm(cbuf, 0x3, 0x5, RSP_enc);
3706     emit_d8(cbuf, 8);
3707 
3708     // movss [rsp], $src
3709     emit_opcode(cbuf, 0xF3);
3710     if (srcenc >= 8) {
3711       emit_opcode(cbuf, Assembler::REX_R);
3712     }
3713     emit_opcode(cbuf, 0x0F);
3714     emit_opcode(cbuf, 0x11);
3715     encode_RegMem(cbuf, srcenc, RSP_enc, 0x4, 0, 0, false); // 2 bytes
3716 
3717     // call f2l_fixup
3718     cbuf.set_insts_mark();
3719     emit_opcode(cbuf, 0xE8);
3720     emit_d32_reloc(cbuf,
3721                    (int)
3722                    (StubRoutines::x86::f2l_fixup() - cbuf.insts_end() - 4),
3723                    runtime_call_Relocation::spec(),
3724                    RELOC_DISP32);
3725 
3726     // popq $dst
3727     if (dstenc >= 8) {
3728       emit_opcode(cbuf, Assembler::REX_B);
3729     }
3730     emit_opcode(cbuf, 0x58 | (dstenc & 7));
3731 
3732     // done:
3733   %}
3734 
3735   enc_class d2i_fixup(rRegI dst, regD src)
3736   %{
3737     int dstenc = $dst$$reg;
3738     int srcenc = $src$$reg;
3739 
3740     // cmpl $dst, #0x80000000
3741     if (dstenc >= 8) {
3742       emit_opcode(cbuf, Assembler::REX_B);
3743     }
3744     emit_opcode(cbuf, 0x81);
3745     emit_rm(cbuf, 0x3, 0x7, dstenc & 7);
3746     emit_d32(cbuf, 0x80000000);
3747 
3748     // jne,s done
3749     emit_opcode(cbuf, 0x75);
3750     if (srcenc < 8 && dstenc < 8) {
3751       emit_d8(cbuf, 0xF);
3752     } else if (srcenc >= 8 && dstenc >= 8) {
3753       emit_d8(cbuf, 0x11);
3754     } else {
3755       emit_d8(cbuf, 0x10);
3756     }
3757 
3758     // subq rsp, #8
3759     emit_opcode(cbuf, Assembler::REX_W);
3760     emit_opcode(cbuf, 0x83);
3761     emit_rm(cbuf, 0x3, 0x5, RSP_enc);
3762     emit_d8(cbuf, 8);
3763 
3764     // movsd [rsp], $src
3765     emit_opcode(cbuf, 0xF2);
3766     if (srcenc >= 8) {
3767       emit_opcode(cbuf, Assembler::REX_R);
3768     }
3769     emit_opcode(cbuf, 0x0F);
3770     emit_opcode(cbuf, 0x11);
3771     encode_RegMem(cbuf, srcenc, RSP_enc, 0x4, 0, 0, false); // 2 bytes
3772 
3773     // call d2i_fixup
3774     cbuf.set_insts_mark();
3775     emit_opcode(cbuf, 0xE8);
3776     emit_d32_reloc(cbuf,
3777                    (int)
3778                    (StubRoutines::x86::d2i_fixup() - cbuf.insts_end() - 4),
3779                    runtime_call_Relocation::spec(),
3780                    RELOC_DISP32);
3781 
3782     // popq $dst
3783     if (dstenc >= 8) {
3784       emit_opcode(cbuf, Assembler::REX_B);
3785     }
3786     emit_opcode(cbuf, 0x58 | (dstenc & 7));
3787 
3788     // done:
3789   %}
3790 
3791   enc_class d2l_fixup(rRegL dst, regD src)
3792   %{
3793     int dstenc = $dst$$reg;
3794     int srcenc = $src$$reg;
3795     address const_address = (address) StubRoutines::x86::double_sign_flip();
3796 
3797     // cmpq $dst, [0x8000000000000000]
3798     cbuf.set_insts_mark();
3799     emit_opcode(cbuf, dstenc < 8 ? Assembler::REX_W : Assembler::REX_WR);
3800     emit_opcode(cbuf, 0x39);
3801     // XXX reg_mem doesn't support RIP-relative addressing yet
3802     emit_rm(cbuf, 0x0, dstenc & 7, 0x5); // 00 reg 101
3803     emit_d32_reloc(cbuf, const_address);
3804 
3805 
3806     // jne,s done
3807     emit_opcode(cbuf, 0x75);
3808     if (srcenc < 8 && dstenc < 8) {
3809       emit_d8(cbuf, 0xF);
3810     } else if (srcenc >= 8 && dstenc >= 8) {
3811       emit_d8(cbuf, 0x11);
3812     } else {
3813       emit_d8(cbuf, 0x10);
3814     }
3815 
3816     // subq rsp, #8
3817     emit_opcode(cbuf, Assembler::REX_W);
3818     emit_opcode(cbuf, 0x83);
3819     emit_rm(cbuf, 0x3, 0x5, RSP_enc);
3820     emit_d8(cbuf, 8);
3821 
3822     // movsd [rsp], $src
3823     emit_opcode(cbuf, 0xF2);
3824     if (srcenc >= 8) {
3825       emit_opcode(cbuf, Assembler::REX_R);
3826     }
3827     emit_opcode(cbuf, 0x0F);
3828     emit_opcode(cbuf, 0x11);
3829     encode_RegMem(cbuf, srcenc, RSP_enc, 0x4, 0, 0, false); // 2 bytes
3830 
3831     // call d2l_fixup
3832     cbuf.set_insts_mark();
3833     emit_opcode(cbuf, 0xE8);
3834     emit_d32_reloc(cbuf,
3835                    (int)
3836                    (StubRoutines::x86::d2l_fixup() - cbuf.insts_end() - 4),
3837                    runtime_call_Relocation::spec(),
3838                    RELOC_DISP32);
3839 
3840     // popq $dst
3841     if (dstenc >= 8) {
3842       emit_opcode(cbuf, Assembler::REX_B);
3843     }
3844     emit_opcode(cbuf, 0x58 | (dstenc & 7));
3845 
3846     // done:
3847   %}
3848 %}
3849 
3850 
3851 
3852 //----------FRAME--------------------------------------------------------------
3853 // Definition of frame structure and management information.
3854 //
3855 //  S T A C K   L A Y O U T    Allocators stack-slot number
3856 //                             |   (to get allocators register number
3857 //  G  Owned by    |        |  v    add OptoReg::stack0())
3858 //  r   CALLER     |        |
3859 //  o     |        +--------+      pad to even-align allocators stack-slot
3860 //  w     V        |  pad0  |        numbers; owned by CALLER
3861 //  t   -----------+--------+----> Matcher::_in_arg_limit, unaligned
3862 //  h     ^        |   in   |  5
3863 //        |        |  args  |  4   Holes in incoming args owned by SELF
3864 //  |     |        |        |  3
3865 //  |     |        +--------+
3866 //  V     |        | old out|      Empty on Intel, window on Sparc
3867 //        |    old |preserve|      Must be even aligned.
3868 //        |     SP-+--------+----> Matcher::_old_SP, even aligned
3869 //        |        |   in   |  3   area for Intel ret address
3870 //     Owned by    |preserve|      Empty on Sparc.
3871 //       SELF      +--------+
3872 //        |        |  pad2  |  2   pad to align old SP
3873 //        |        +--------+  1
3874 //        |        | locks  |  0
3875 //        |        +--------+----> OptoReg::stack0(), even aligned
3876 //        |        |  pad1  | 11   pad to align new SP
3877 //        |        +--------+
3878 //        |        |        | 10
3879 //        |        | spills |  9   spills
3880 //        V        |        |  8   (pad0 slot for callee)
3881 //      -----------+--------+----> Matcher::_out_arg_limit, unaligned
3882 //        ^        |  out   |  7
3883 //        |        |  args  |  6   Holes in outgoing args owned by CALLEE
3884 //     Owned by    +--------+
3885 //      CALLEE     | new out|  6   Empty on Intel, window on Sparc
3886 //        |    new |preserve|      Must be even-aligned.
3887 //        |     SP-+--------+----> Matcher::_new_SP, even aligned
3888 //        |        |        |
3889 //
3890 // Note 1: Only region 8-11 is determined by the allocator.  Region 0-5 is
3891 //         known from SELF's arguments and the Java calling convention.
3892 //         Region 6-7 is determined per call site.
3893 // Note 2: If the calling convention leaves holes in the incoming argument
3894 //         area, those holes are owned by SELF.  Holes in the outgoing area
3895 //         are owned by the CALLEE.  Holes should not be nessecary in the
3896 //         incoming area, as the Java calling convention is completely under
3897 //         the control of the AD file.  Doubles can be sorted and packed to
3898 //         avoid holes.  Holes in the outgoing arguments may be nessecary for
3899 //         varargs C calling conventions.
3900 // Note 3: Region 0-3 is even aligned, with pad2 as needed.  Region 3-5 is
3901 //         even aligned with pad0 as needed.
3902 //         Region 6 is even aligned.  Region 6-7 is NOT even aligned;
3903 //         region 6-11 is even aligned; it may be padded out more so that
3904 //         the region from SP to FP meets the minimum stack alignment.
3905 // Note 4: For I2C adapters, the incoming FP may not meet the minimum stack
3906 //         alignment.  Region 11, pad1, may be dynamically extended so that
3907 //         SP meets the minimum alignment.
3908 
3909 frame
3910 %{
3911   // What direction does stack grow in (assumed to be same for C & Java)
3912   stack_direction(TOWARDS_LOW);
3913 
3914   // These three registers define part of the calling convention
3915   // between compiled code and the interpreter.
3916   inline_cache_reg(RAX);                // Inline Cache Register
3917   interpreter_method_oop_reg(RBX);      // Method Oop Register when
3918                                         // calling interpreter
3919 
3920   // Optional: name the operand used by cisc-spilling to access
3921   // [stack_pointer + offset]
3922   cisc_spilling_operand_name(indOffset32);
3923 
3924   // Number of stack slots consumed by locking an object
3925   sync_stack_slots(2);
3926 
3927   // Compiled code's Frame Pointer
3928   frame_pointer(RSP);
3929 
3930   // Interpreter stores its frame pointer in a register which is
3931   // stored to the stack by I2CAdaptors.
3932   // I2CAdaptors convert from interpreted java to compiled java.
3933   interpreter_frame_pointer(RBP);
3934 
3935   // Stack alignment requirement
3936   stack_alignment(StackAlignmentInBytes); // Alignment size in bytes (128-bit -> 16 bytes)
3937 
3938   // Number of stack slots between incoming argument block and the start of
3939   // a new frame.  The PROLOG must add this many slots to the stack.  The
3940   // EPILOG must remove this many slots.  amd64 needs two slots for
3941   // return address.
3942   in_preserve_stack_slots(4 + 2 * VerifyStackAtCalls);
3943 
3944   // Number of outgoing stack slots killed above the out_preserve_stack_slots
3945   // for calls to C.  Supports the var-args backing area for register parms.
3946   varargs_C_out_slots_killed(frame::arg_reg_save_area_bytes/BytesPerInt);
3947 
3948   // The after-PROLOG location of the return address.  Location of
3949   // return address specifies a type (REG or STACK) and a number
3950   // representing the register number (i.e. - use a register name) or
3951   // stack slot.
3952   // Ret Addr is on stack in slot 0 if no locks or verification or alignment.
3953   // Otherwise, it is above the locks and verification slot and alignment word
3954   return_addr(STACK - 2 +
3955               round_to(2 + 2 * VerifyStackAtCalls +
3956                        Compile::current()->fixed_slots(),
3957                        WordsPerLong * 2));
3958 
3959   // Body of function which returns an integer array locating
3960   // arguments either in registers or in stack slots.  Passed an array
3961   // of ideal registers called "sig" and a "length" count.  Stack-slot
3962   // offsets are based on outgoing arguments, i.e. a CALLER setting up
3963   // arguments for a CALLEE.  Incoming stack arguments are
3964   // automatically biased by the preserve_stack_slots field above.
3965 
3966   calling_convention
3967   %{
3968     // No difference between ingoing/outgoing just pass false
3969     SharedRuntime::java_calling_convention(sig_bt, regs, length, false);
3970   %}
3971 
3972   c_calling_convention
3973   %{
3974     // This is obviously always outgoing
3975     (void) SharedRuntime::c_calling_convention(sig_bt, regs, length);
3976   %}
3977 
3978   // Location of compiled Java return values.  Same as C for now.
3979   return_value
3980   %{
3981     assert(ideal_reg >= Op_RegI && ideal_reg <= Op_RegL,
3982            "only return normal values");
3983 
3984     static const int lo[Op_RegL + 1] = {
3985       0,
3986       0,
3987       RAX_num,  // Op_RegN
3988       RAX_num,  // Op_RegI
3989       RAX_num,  // Op_RegP
3990       XMM0_num, // Op_RegF
3991       XMM0_num, // Op_RegD
3992       RAX_num   // Op_RegL
3993     };
3994     static const int hi[Op_RegL + 1] = {
3995       0,
3996       0,
3997       OptoReg::Bad, // Op_RegN
3998       OptoReg::Bad, // Op_RegI
3999       RAX_H_num,    // Op_RegP
4000       OptoReg::Bad, // Op_RegF
4001       XMM0_H_num,   // Op_RegD
4002       RAX_H_num     // Op_RegL
4003     };
4004     assert(ARRAY_SIZE(hi) == _last_machine_leaf - 1, "missing type");
4005     return OptoRegPair(hi[ideal_reg], lo[ideal_reg]);
4006   %}
4007 %}
4008 
4009 //----------ATTRIBUTES---------------------------------------------------------
4010 //----------Operand Attributes-------------------------------------------------
4011 op_attrib op_cost(0);        // Required cost attribute
4012 
4013 //----------Instruction Attributes---------------------------------------------
4014 ins_attrib ins_cost(100);       // Required cost attribute
4015 ins_attrib ins_size(8);         // Required size attribute (in bits)
4016 ins_attrib ins_short_branch(0); // Required flag: is this instruction
4017                                 // a non-matching short branch variant
4018                                 // of some long branch?
4019 ins_attrib ins_alignment(1);    // Required alignment attribute (must
4020                                 // be a power of 2) specifies the
4021                                 // alignment that some part of the
4022                                 // instruction (not necessarily the
4023                                 // start) requires.  If > 1, a
4024                                 // compute_padding() function must be
4025                                 // provided for the instruction
4026 
4027 //----------OPERANDS-----------------------------------------------------------
4028 // Operand definitions must precede instruction definitions for correct parsing
4029 // in the ADLC because operands constitute user defined types which are used in
4030 // instruction definitions.
4031 
4032 //----------Simple Operands----------------------------------------------------
4033 // Immediate Operands
4034 // Integer Immediate
4035 operand immI()
4036 %{
4037   match(ConI);
4038 
4039   op_cost(10);
4040   format %{ %}
4041   interface(CONST_INTER);
4042 %}
4043 
4044 // Constant for test vs zero
4045 operand immI0()
4046 %{
4047   predicate(n->get_int() == 0);
4048   match(ConI);
4049 
4050   op_cost(0);
4051   format %{ %}
4052   interface(CONST_INTER);
4053 %}
4054 
4055 // Constant for increment
4056 operand immI1()
4057 %{
4058   predicate(n->get_int() == 1);
4059   match(ConI);
4060 
4061   op_cost(0);
4062   format %{ %}
4063   interface(CONST_INTER);
4064 %}
4065 
4066 // Constant for decrement
4067 operand immI_M1()
4068 %{
4069   predicate(n->get_int() == -1);
4070   match(ConI);
4071 
4072   op_cost(0);
4073   format %{ %}
4074   interface(CONST_INTER);
4075 %}
4076 
4077 // Valid scale values for addressing modes
4078 operand immI2()
4079 %{
4080   predicate(0 <= n->get_int() && (n->get_int() <= 3));
4081   match(ConI);
4082 
4083   format %{ %}
4084   interface(CONST_INTER);
4085 %}
4086 
4087 operand immI8()
4088 %{
4089   predicate((-0x80 <= n->get_int()) && (n->get_int() < 0x80));
4090   match(ConI);
4091 
4092   op_cost(5);
4093   format %{ %}
4094   interface(CONST_INTER);
4095 %}
4096 
4097 operand immI16()
4098 %{
4099   predicate((-32768 <= n->get_int()) && (n->get_int() <= 32767));
4100   match(ConI);
4101 
4102   op_cost(10);
4103   format %{ %}
4104   interface(CONST_INTER);
4105 %}
4106 
4107 // Constant for long shifts
4108 operand immI_32()
4109 %{
4110   predicate( n->get_int() == 32 );
4111   match(ConI);
4112 
4113   op_cost(0);
4114   format %{ %}
4115   interface(CONST_INTER);
4116 %}
4117 
4118 // Constant for long shifts
4119 operand immI_64()
4120 %{
4121   predicate( n->get_int() == 64 );
4122   match(ConI);
4123 
4124   op_cost(0);
4125   format %{ %}
4126   interface(CONST_INTER);
4127 %}
4128 
4129 // Pointer Immediate
4130 operand immP()
4131 %{
4132   match(ConP);
4133 
4134   op_cost(10);
4135   format %{ %}
4136   interface(CONST_INTER);
4137 %}
4138 
4139 // NULL Pointer Immediate
4140 operand immP0()
4141 %{
4142   predicate(n->get_ptr() == 0);
4143   match(ConP);
4144 
4145   op_cost(5);
4146   format %{ %}
4147   interface(CONST_INTER);
4148 %}
4149 
4150 operand immP_poll() %{
4151   predicate(n->get_ptr() != 0 && n->get_ptr() == (intptr_t)os::get_polling_page());
4152   match(ConP);
4153 
4154   // formats are generated automatically for constants and base registers
4155   format %{ %}
4156   interface(CONST_INTER);
4157 %}
4158 
4159 // Pointer Immediate
4160 operand immN() %{
4161   match(ConN);
4162 
4163   op_cost(10);
4164   format %{ %}
4165   interface(CONST_INTER);
4166 %}
4167 
4168 // NULL Pointer Immediate
4169 operand immN0() %{
4170   predicate(n->get_narrowcon() == 0);
4171   match(ConN);
4172 
4173   op_cost(5);
4174   format %{ %}
4175   interface(CONST_INTER);
4176 %}
4177 
4178 operand immP31()
4179 %{
4180   predicate(!n->as_Type()->type()->isa_oopptr()
4181             && (n->get_ptr() >> 31) == 0);
4182   match(ConP);
4183 
4184   op_cost(5);
4185   format %{ %}
4186   interface(CONST_INTER);
4187 %}
4188 
4189 
4190 // Long Immediate
4191 operand immL()
4192 %{
4193   match(ConL);
4194 
4195   op_cost(20);
4196   format %{ %}
4197   interface(CONST_INTER);
4198 %}
4199 
4200 // Long Immediate 8-bit
4201 operand immL8()
4202 %{
4203   predicate(-0x80L <= n->get_long() && n->get_long() < 0x80L);
4204   match(ConL);
4205 
4206   op_cost(5);
4207   format %{ %}
4208   interface(CONST_INTER);
4209 %}
4210 
4211 // Long Immediate 32-bit unsigned
4212 operand immUL32()
4213 %{
4214   predicate(n->get_long() == (unsigned int) (n->get_long()));
4215   match(ConL);
4216 
4217   op_cost(10);
4218   format %{ %}
4219   interface(CONST_INTER);
4220 %}
4221 
4222 // Long Immediate 32-bit signed
4223 operand immL32()
4224 %{
4225   predicate(n->get_long() == (int) (n->get_long()));
4226   match(ConL);
4227 
4228   op_cost(15);
4229   format %{ %}
4230   interface(CONST_INTER);
4231 %}
4232 
4233 // Long Immediate zero
4234 operand immL0()
4235 %{
4236   predicate(n->get_long() == 0L);
4237   match(ConL);
4238 
4239   op_cost(10);
4240   format %{ %}
4241   interface(CONST_INTER);
4242 %}
4243 
4244 // Constant for increment
4245 operand immL1()
4246 %{
4247   predicate(n->get_long() == 1);
4248   match(ConL);
4249 
4250   format %{ %}
4251   interface(CONST_INTER);
4252 %}
4253 
4254 // Constant for decrement
4255 operand immL_M1()
4256 %{
4257   predicate(n->get_long() == -1);
4258   match(ConL);
4259 
4260   format %{ %}
4261   interface(CONST_INTER);
4262 %}
4263 
4264 // Long Immediate: the value 10
4265 operand immL10()
4266 %{
4267   predicate(n->get_long() == 10);
4268   match(ConL);
4269 
4270   format %{ %}
4271   interface(CONST_INTER);
4272 %}
4273 
4274 // Long immediate from 0 to 127.
4275 // Used for a shorter form of long mul by 10.
4276 operand immL_127()
4277 %{
4278   predicate(0 <= n->get_long() && n->get_long() < 0x80);
4279   match(ConL);
4280 
4281   op_cost(10);
4282   format %{ %}
4283   interface(CONST_INTER);
4284 %}
4285 
4286 // Long Immediate: low 32-bit mask
4287 operand immL_32bits()
4288 %{
4289   predicate(n->get_long() == 0xFFFFFFFFL);
4290   match(ConL);
4291   op_cost(20);
4292 
4293   format %{ %}
4294   interface(CONST_INTER);
4295 %}
4296 
4297 // Float Immediate zero
4298 operand immF0()
4299 %{
4300   predicate(jint_cast(n->getf()) == 0);
4301   match(ConF);
4302 
4303   op_cost(5);
4304   format %{ %}
4305   interface(CONST_INTER);
4306 %}
4307 
4308 // Float Immediate
4309 operand immF()
4310 %{
4311   match(ConF);
4312 
4313   op_cost(15);
4314   format %{ %}
4315   interface(CONST_INTER);
4316 %}
4317 
4318 // Double Immediate zero
4319 operand immD0()
4320 %{
4321   predicate(jlong_cast(n->getd()) == 0);
4322   match(ConD);
4323 
4324   op_cost(5);
4325   format %{ %}
4326   interface(CONST_INTER);
4327 %}
4328 
4329 // Double Immediate
4330 operand immD()
4331 %{
4332   match(ConD);
4333 
4334   op_cost(15);
4335   format %{ %}
4336   interface(CONST_INTER);
4337 %}
4338 
4339 // Immediates for special shifts (sign extend)
4340 
4341 // Constants for increment
4342 operand immI_16()
4343 %{
4344   predicate(n->get_int() == 16);
4345   match(ConI);
4346 
4347   format %{ %}
4348   interface(CONST_INTER);
4349 %}
4350 
4351 operand immI_24()
4352 %{
4353   predicate(n->get_int() == 24);
4354   match(ConI);
4355 
4356   format %{ %}
4357   interface(CONST_INTER);
4358 %}
4359 
4360 // Constant for byte-wide masking
4361 operand immI_255()
4362 %{
4363   predicate(n->get_int() == 255);
4364   match(ConI);
4365 
4366   format %{ %}
4367   interface(CONST_INTER);
4368 %}
4369 
4370 // Constant for short-wide masking
4371 operand immI_65535()
4372 %{
4373   predicate(n->get_int() == 65535);
4374   match(ConI);
4375 
4376   format %{ %}
4377   interface(CONST_INTER);
4378 %}
4379 
4380 // Constant for byte-wide masking
4381 operand immL_255()
4382 %{
4383   predicate(n->get_long() == 255);
4384   match(ConL);
4385 
4386   format %{ %}
4387   interface(CONST_INTER);
4388 %}
4389 
4390 // Constant for short-wide masking
4391 operand immL_65535()
4392 %{
4393   predicate(n->get_long() == 65535);
4394   match(ConL);
4395 
4396   format %{ %}
4397   interface(CONST_INTER);
4398 %}
4399 
4400 // Register Operands
4401 // Integer Register
4402 operand rRegI()
4403 %{
4404   constraint(ALLOC_IN_RC(int_reg));
4405   match(RegI);
4406 
4407   match(rax_RegI);
4408   match(rbx_RegI);
4409   match(rcx_RegI);
4410   match(rdx_RegI);
4411   match(rdi_RegI);
4412 
4413   format %{ %}
4414   interface(REG_INTER);
4415 %}
4416 
4417 // Special Registers
4418 operand rax_RegI()
4419 %{
4420   constraint(ALLOC_IN_RC(int_rax_reg));
4421   match(RegI);
4422   match(rRegI);
4423 
4424   format %{ "RAX" %}
4425   interface(REG_INTER);
4426 %}
4427 
4428 // Special Registers
4429 operand rbx_RegI()
4430 %{
4431   constraint(ALLOC_IN_RC(int_rbx_reg));
4432   match(RegI);
4433   match(rRegI);
4434 
4435   format %{ "RBX" %}
4436   interface(REG_INTER);
4437 %}
4438 
4439 operand rcx_RegI()
4440 %{
4441   constraint(ALLOC_IN_RC(int_rcx_reg));
4442   match(RegI);
4443   match(rRegI);
4444 
4445   format %{ "RCX" %}
4446   interface(REG_INTER);
4447 %}
4448 
4449 operand rdx_RegI()
4450 %{
4451   constraint(ALLOC_IN_RC(int_rdx_reg));
4452   match(RegI);
4453   match(rRegI);
4454 
4455   format %{ "RDX" %}
4456   interface(REG_INTER);
4457 %}
4458 
4459 operand rdi_RegI()
4460 %{
4461   constraint(ALLOC_IN_RC(int_rdi_reg));
4462   match(RegI);
4463   match(rRegI);
4464 
4465   format %{ "RDI" %}
4466   interface(REG_INTER);
4467 %}
4468 
4469 operand no_rcx_RegI()
4470 %{
4471   constraint(ALLOC_IN_RC(int_no_rcx_reg));
4472   match(RegI);
4473   match(rax_RegI);
4474   match(rbx_RegI);
4475   match(rdx_RegI);
4476   match(rdi_RegI);
4477 
4478   format %{ %}
4479   interface(REG_INTER);
4480 %}
4481 
4482 operand no_rax_rdx_RegI()
4483 %{
4484   constraint(ALLOC_IN_RC(int_no_rax_rdx_reg));
4485   match(RegI);
4486   match(rbx_RegI);
4487   match(rcx_RegI);
4488   match(rdi_RegI);
4489 
4490   format %{ %}
4491   interface(REG_INTER);
4492 %}
4493 
4494 // Pointer Register
4495 operand any_RegP()
4496 %{
4497   constraint(ALLOC_IN_RC(any_reg));
4498   match(RegP);
4499   match(rax_RegP);
4500   match(rbx_RegP);
4501   match(rdi_RegP);
4502   match(rsi_RegP);
4503   match(rbp_RegP);
4504   match(r15_RegP);
4505   match(rRegP);
4506 
4507   format %{ %}
4508   interface(REG_INTER);
4509 %}
4510 
4511 operand rRegP()
4512 %{
4513   constraint(ALLOC_IN_RC(ptr_reg));
4514   match(RegP);
4515   match(rax_RegP);
4516   match(rbx_RegP);
4517   match(rdi_RegP);
4518   match(rsi_RegP);
4519   match(rbp_RegP);
4520   match(r15_RegP);  // See Q&A below about r15_RegP.
4521 
4522   format %{ %}
4523   interface(REG_INTER);
4524 %}
4525 
4526 operand rRegN() %{
4527   constraint(ALLOC_IN_RC(int_reg));
4528   match(RegN);
4529 
4530   format %{ %}
4531   interface(REG_INTER);
4532 %}
4533 
4534 // Question: Why is r15_RegP (the read-only TLS register) a match for rRegP?
4535 // Answer: Operand match rules govern the DFA as it processes instruction inputs.
4536 // It's fine for an instruction input which expects rRegP to match a r15_RegP.
4537 // The output of an instruction is controlled by the allocator, which respects
4538 // register class masks, not match rules.  Unless an instruction mentions
4539 // r15_RegP or any_RegP explicitly as its output, r15 will not be considered
4540 // by the allocator as an input.
4541 
4542 operand no_rax_RegP()
4543 %{
4544   constraint(ALLOC_IN_RC(ptr_no_rax_reg));
4545   match(RegP);
4546   match(rbx_RegP);
4547   match(rsi_RegP);
4548   match(rdi_RegP);
4549 
4550   format %{ %}
4551   interface(REG_INTER);
4552 %}
4553 
4554 operand no_rbp_RegP()
4555 %{
4556   constraint(ALLOC_IN_RC(ptr_no_rbp_reg));
4557   match(RegP);
4558   match(rbx_RegP);
4559   match(rsi_RegP);
4560   match(rdi_RegP);
4561 
4562   format %{ %}
4563   interface(REG_INTER);
4564 %}
4565 
4566 operand no_rax_rbx_RegP()
4567 %{
4568   constraint(ALLOC_IN_RC(ptr_no_rax_rbx_reg));
4569   match(RegP);
4570   match(rsi_RegP);
4571   match(rdi_RegP);
4572 
4573   format %{ %}
4574   interface(REG_INTER);
4575 %}
4576 
4577 // Special Registers
4578 // Return a pointer value
4579 operand rax_RegP()
4580 %{
4581   constraint(ALLOC_IN_RC(ptr_rax_reg));
4582   match(RegP);
4583   match(rRegP);
4584 
4585   format %{ %}
4586   interface(REG_INTER);
4587 %}
4588 
4589 // Special Registers
4590 // Return a compressed pointer value
4591 operand rax_RegN()
4592 %{
4593   constraint(ALLOC_IN_RC(int_rax_reg));
4594   match(RegN);
4595   match(rRegN);
4596 
4597   format %{ %}
4598   interface(REG_INTER);
4599 %}
4600 
4601 // Used in AtomicAdd
4602 operand rbx_RegP()
4603 %{
4604   constraint(ALLOC_IN_RC(ptr_rbx_reg));
4605   match(RegP);
4606   match(rRegP);
4607 
4608   format %{ %}
4609   interface(REG_INTER);
4610 %}
4611 
4612 operand rsi_RegP()
4613 %{
4614   constraint(ALLOC_IN_RC(ptr_rsi_reg));
4615   match(RegP);
4616   match(rRegP);
4617 
4618   format %{ %}
4619   interface(REG_INTER);
4620 %}
4621 
4622 // Used in rep stosq
4623 operand rdi_RegP()
4624 %{
4625   constraint(ALLOC_IN_RC(ptr_rdi_reg));
4626   match(RegP);
4627   match(rRegP);
4628 
4629   format %{ %}
4630   interface(REG_INTER);
4631 %}
4632 
4633 operand rbp_RegP()
4634 %{
4635   constraint(ALLOC_IN_RC(ptr_rbp_reg));
4636   match(RegP);
4637   match(rRegP);
4638 
4639   format %{ %}
4640   interface(REG_INTER);
4641 %}
4642 
4643 operand r15_RegP()
4644 %{
4645   constraint(ALLOC_IN_RC(ptr_r15_reg));
4646   match(RegP);
4647   match(rRegP);
4648 
4649   format %{ %}
4650   interface(REG_INTER);
4651 %}
4652 
4653 operand rRegL()
4654 %{
4655   constraint(ALLOC_IN_RC(long_reg));
4656   match(RegL);
4657   match(rax_RegL);
4658   match(rdx_RegL);
4659 
4660   format %{ %}
4661   interface(REG_INTER);
4662 %}
4663 
4664 // Special Registers
4665 operand no_rax_rdx_RegL()
4666 %{
4667   constraint(ALLOC_IN_RC(long_no_rax_rdx_reg));
4668   match(RegL);
4669   match(rRegL);
4670 
4671   format %{ %}
4672   interface(REG_INTER);
4673 %}
4674 
4675 operand no_rax_RegL()
4676 %{
4677   constraint(ALLOC_IN_RC(long_no_rax_rdx_reg));
4678   match(RegL);
4679   match(rRegL);
4680   match(rdx_RegL);
4681 
4682   format %{ %}
4683   interface(REG_INTER);
4684 %}
4685 
4686 operand no_rcx_RegL()
4687 %{
4688   constraint(ALLOC_IN_RC(long_no_rcx_reg));
4689   match(RegL);
4690   match(rRegL);
4691 
4692   format %{ %}
4693   interface(REG_INTER);
4694 %}
4695 
4696 operand rax_RegL()
4697 %{
4698   constraint(ALLOC_IN_RC(long_rax_reg));
4699   match(RegL);
4700   match(rRegL);
4701 
4702   format %{ "RAX" %}
4703   interface(REG_INTER);
4704 %}
4705 
4706 operand rcx_RegL()
4707 %{
4708   constraint(ALLOC_IN_RC(long_rcx_reg));
4709   match(RegL);
4710   match(rRegL);
4711 
4712   format %{ %}
4713   interface(REG_INTER);
4714 %}
4715 
4716 operand rdx_RegL()
4717 %{
4718   constraint(ALLOC_IN_RC(long_rdx_reg));
4719   match(RegL);
4720   match(rRegL);
4721 
4722   format %{ %}
4723   interface(REG_INTER);
4724 %}
4725 
4726 // Flags register, used as output of compare instructions
4727 operand rFlagsReg()
4728 %{
4729   constraint(ALLOC_IN_RC(int_flags));
4730   match(RegFlags);
4731 
4732   format %{ "RFLAGS" %}
4733   interface(REG_INTER);
4734 %}
4735 
4736 // Flags register, used as output of FLOATING POINT compare instructions
4737 operand rFlagsRegU()
4738 %{
4739   constraint(ALLOC_IN_RC(int_flags));
4740   match(RegFlags);
4741 
4742   format %{ "RFLAGS_U" %}
4743   interface(REG_INTER);
4744 %}
4745 
4746 operand rFlagsRegUCF() %{
4747   constraint(ALLOC_IN_RC(int_flags));
4748   match(RegFlags);
4749   predicate(false);
4750 
4751   format %{ "RFLAGS_U_CF" %}
4752   interface(REG_INTER);
4753 %}
4754 
4755 // Float register operands
4756 operand regF()
4757 %{
4758   constraint(ALLOC_IN_RC(float_reg));
4759   match(RegF);
4760 
4761   format %{ %}
4762   interface(REG_INTER);
4763 %}
4764 
4765 // Double register operands
4766 operand regD()
4767 %{
4768   constraint(ALLOC_IN_RC(double_reg));
4769   match(RegD);
4770 
4771   format %{ %}
4772   interface(REG_INTER);
4773 %}
4774 
4775 
4776 //----------Memory Operands----------------------------------------------------
4777 // Direct Memory Operand
4778 // operand direct(immP addr)
4779 // %{
4780 //   match(addr);
4781 
4782 //   format %{ "[$addr]" %}
4783 //   interface(MEMORY_INTER) %{
4784 //     base(0xFFFFFFFF);
4785 //     index(0x4);
4786 //     scale(0x0);
4787 //     disp($addr);
4788 //   %}
4789 // %}
4790 
4791 // Indirect Memory Operand
4792 operand indirect(any_RegP reg)
4793 %{
4794   constraint(ALLOC_IN_RC(ptr_reg));
4795   match(reg);
4796 
4797   format %{ "[$reg]" %}
4798   interface(MEMORY_INTER) %{
4799     base($reg);
4800     index(0x4);
4801     scale(0x0);
4802     disp(0x0);
4803   %}
4804 %}
4805 
4806 // Indirect Memory Plus Short Offset Operand
4807 operand indOffset8(any_RegP reg, immL8 off)
4808 %{
4809   constraint(ALLOC_IN_RC(ptr_reg));
4810   match(AddP reg off);
4811 
4812   format %{ "[$reg + $off (8-bit)]" %}
4813   interface(MEMORY_INTER) %{
4814     base($reg);
4815     index(0x4);
4816     scale(0x0);
4817     disp($off);
4818   %}
4819 %}
4820 
4821 // Indirect Memory Plus Long Offset Operand
4822 operand indOffset32(any_RegP reg, immL32 off)
4823 %{
4824   constraint(ALLOC_IN_RC(ptr_reg));
4825   match(AddP reg off);
4826 
4827   format %{ "[$reg + $off (32-bit)]" %}
4828   interface(MEMORY_INTER) %{
4829     base($reg);
4830     index(0x4);
4831     scale(0x0);
4832     disp($off);
4833   %}
4834 %}
4835 
4836 // Indirect Memory Plus Index Register Plus Offset Operand
4837 operand indIndexOffset(any_RegP reg, rRegL lreg, immL32 off)
4838 %{
4839   constraint(ALLOC_IN_RC(ptr_reg));
4840   match(AddP (AddP reg lreg) off);
4841 
4842   op_cost(10);
4843   format %{"[$reg + $off + $lreg]" %}
4844   interface(MEMORY_INTER) %{
4845     base($reg);
4846     index($lreg);
4847     scale(0x0);
4848     disp($off);
4849   %}
4850 %}
4851 
4852 // Indirect Memory Plus Index Register Plus Offset Operand
4853 operand indIndex(any_RegP reg, rRegL lreg)
4854 %{
4855   constraint(ALLOC_IN_RC(ptr_reg));
4856   match(AddP reg lreg);
4857 
4858   op_cost(10);
4859   format %{"[$reg + $lreg]" %}
4860   interface(MEMORY_INTER) %{
4861     base($reg);
4862     index($lreg);
4863     scale(0x0);
4864     disp(0x0);
4865   %}
4866 %}
4867 
4868 // Indirect Memory Times Scale Plus Index Register
4869 operand indIndexScale(any_RegP reg, rRegL lreg, immI2 scale)
4870 %{
4871   constraint(ALLOC_IN_RC(ptr_reg));
4872   match(AddP reg (LShiftL lreg scale));
4873 
4874   op_cost(10);
4875   format %{"[$reg + $lreg << $scale]" %}
4876   interface(MEMORY_INTER) %{
4877     base($reg);
4878     index($lreg);
4879     scale($scale);
4880     disp(0x0);
4881   %}
4882 %}
4883 
4884 // Indirect Memory Times Scale Plus Index Register Plus Offset Operand
4885 operand indIndexScaleOffset(any_RegP reg, immL32 off, rRegL lreg, immI2 scale)
4886 %{
4887   constraint(ALLOC_IN_RC(ptr_reg));
4888   match(AddP (AddP reg (LShiftL lreg scale)) off);
4889 
4890   op_cost(10);
4891   format %{"[$reg + $off + $lreg << $scale]" %}
4892   interface(MEMORY_INTER) %{
4893     base($reg);
4894     index($lreg);
4895     scale($scale);
4896     disp($off);
4897   %}
4898 %}
4899 
4900 // Indirect Memory Times Scale Plus Positive Index Register Plus Offset Operand
4901 operand indPosIndexScaleOffset(any_RegP reg, immL32 off, rRegI idx, immI2 scale)
4902 %{
4903   constraint(ALLOC_IN_RC(ptr_reg));
4904   predicate(n->in(2)->in(3)->in(1)->as_Type()->type()->is_long()->_lo >= 0);
4905   match(AddP (AddP reg (LShiftL (ConvI2L idx) scale)) off);
4906 
4907   op_cost(10);
4908   format %{"[$reg + $off + $idx << $scale]" %}
4909   interface(MEMORY_INTER) %{
4910     base($reg);
4911     index($idx);
4912     scale($scale);
4913     disp($off);
4914   %}
4915 %}
4916 
4917 // Indirect Narrow Oop Plus Offset Operand
4918 // Note: x86 architecture doesn't support "scale * index + offset" without a base
4919 // we can't free r12 even with Universe::narrow_oop_base() == NULL.
4920 operand indCompressedOopOffset(rRegN reg, immL32 off) %{
4921   predicate(UseCompressedOops && (Universe::narrow_oop_shift() == Address::times_8));
4922   constraint(ALLOC_IN_RC(ptr_reg));
4923   match(AddP (DecodeN reg) off);
4924 
4925   op_cost(10);
4926   format %{"[R12 + $reg << 3 + $off] (compressed oop addressing)" %}
4927   interface(MEMORY_INTER) %{
4928     base(0xc); // R12
4929     index($reg);
4930     scale(0x3);
4931     disp($off);
4932   %}
4933 %}
4934 
4935 // Indirect Memory Operand
4936 operand indirectNarrow(rRegN reg)
4937 %{
4938   predicate(Universe::narrow_oop_shift() == 0);
4939   constraint(ALLOC_IN_RC(ptr_reg));
4940   match(DecodeN reg);
4941 
4942   format %{ "[$reg]" %}
4943   interface(MEMORY_INTER) %{
4944     base($reg);
4945     index(0x4);
4946     scale(0x0);
4947     disp(0x0);
4948   %}
4949 %}
4950 
4951 // Indirect Memory Plus Short Offset Operand
4952 operand indOffset8Narrow(rRegN reg, immL8 off)
4953 %{
4954   predicate(Universe::narrow_oop_shift() == 0);
4955   constraint(ALLOC_IN_RC(ptr_reg));
4956   match(AddP (DecodeN reg) off);
4957 
4958   format %{ "[$reg + $off (8-bit)]" %}
4959   interface(MEMORY_INTER) %{
4960     base($reg);
4961     index(0x4);
4962     scale(0x0);
4963     disp($off);
4964   %}
4965 %}
4966 
4967 // Indirect Memory Plus Long Offset Operand
4968 operand indOffset32Narrow(rRegN reg, immL32 off)
4969 %{
4970   predicate(Universe::narrow_oop_shift() == 0);
4971   constraint(ALLOC_IN_RC(ptr_reg));
4972   match(AddP (DecodeN reg) off);
4973 
4974   format %{ "[$reg + $off (32-bit)]" %}
4975   interface(MEMORY_INTER) %{
4976     base($reg);
4977     index(0x4);
4978     scale(0x0);
4979     disp($off);
4980   %}
4981 %}
4982 
4983 // Indirect Memory Plus Index Register Plus Offset Operand
4984 operand indIndexOffsetNarrow(rRegN reg, rRegL lreg, immL32 off)
4985 %{
4986   predicate(Universe::narrow_oop_shift() == 0);
4987   constraint(ALLOC_IN_RC(ptr_reg));
4988   match(AddP (AddP (DecodeN reg) lreg) off);
4989 
4990   op_cost(10);
4991   format %{"[$reg + $off + $lreg]" %}
4992   interface(MEMORY_INTER) %{
4993     base($reg);
4994     index($lreg);
4995     scale(0x0);
4996     disp($off);
4997   %}
4998 %}
4999 
5000 // Indirect Memory Plus Index Register Plus Offset Operand
5001 operand indIndexNarrow(rRegN reg, rRegL lreg)
5002 %{
5003   predicate(Universe::narrow_oop_shift() == 0);
5004   constraint(ALLOC_IN_RC(ptr_reg));
5005   match(AddP (DecodeN reg) lreg);
5006 
5007   op_cost(10);
5008   format %{"[$reg + $lreg]" %}
5009   interface(MEMORY_INTER) %{
5010     base($reg);
5011     index($lreg);
5012     scale(0x0);
5013     disp(0x0);
5014   %}
5015 %}
5016 
5017 // Indirect Memory Times Scale Plus Index Register
5018 operand indIndexScaleNarrow(rRegN reg, rRegL lreg, immI2 scale)
5019 %{
5020   predicate(Universe::narrow_oop_shift() == 0);
5021   constraint(ALLOC_IN_RC(ptr_reg));
5022   match(AddP (DecodeN reg) (LShiftL lreg scale));
5023 
5024   op_cost(10);
5025   format %{"[$reg + $lreg << $scale]" %}
5026   interface(MEMORY_INTER) %{
5027     base($reg);
5028     index($lreg);
5029     scale($scale);
5030     disp(0x0);
5031   %}
5032 %}
5033 
5034 // Indirect Memory Times Scale Plus Index Register Plus Offset Operand
5035 operand indIndexScaleOffsetNarrow(rRegN reg, immL32 off, rRegL lreg, immI2 scale)
5036 %{
5037   predicate(Universe::narrow_oop_shift() == 0);
5038   constraint(ALLOC_IN_RC(ptr_reg));
5039   match(AddP (AddP (DecodeN reg) (LShiftL lreg scale)) off);
5040 
5041   op_cost(10);
5042   format %{"[$reg + $off + $lreg << $scale]" %}
5043   interface(MEMORY_INTER) %{
5044     base($reg);
5045     index($lreg);
5046     scale($scale);
5047     disp($off);
5048   %}
5049 %}
5050 
5051 // Indirect Memory Times Scale Plus Positive Index Register Plus Offset Operand
5052 operand indPosIndexScaleOffsetNarrow(rRegN reg, immL32 off, rRegI idx, immI2 scale)
5053 %{
5054   constraint(ALLOC_IN_RC(ptr_reg));
5055   predicate(Universe::narrow_oop_shift() == 0 && n->in(2)->in(3)->in(1)->as_Type()->type()->is_long()->_lo >= 0);
5056   match(AddP (AddP (DecodeN reg) (LShiftL (ConvI2L idx) scale)) off);
5057 
5058   op_cost(10);
5059   format %{"[$reg + $off + $idx << $scale]" %}
5060   interface(MEMORY_INTER) %{
5061     base($reg);
5062     index($idx);
5063     scale($scale);
5064     disp($off);
5065   %}
5066 %}
5067 
5068 
5069 //----------Special Memory Operands--------------------------------------------
5070 // Stack Slot Operand - This operand is used for loading and storing temporary
5071 //                      values on the stack where a match requires a value to
5072 //                      flow through memory.
5073 operand stackSlotP(sRegP reg)
5074 %{
5075   constraint(ALLOC_IN_RC(stack_slots));
5076   // No match rule because this operand is only generated in matching
5077 
5078   format %{ "[$reg]" %}
5079   interface(MEMORY_INTER) %{
5080     base(0x4);   // RSP
5081     index(0x4);  // No Index
5082     scale(0x0);  // No Scale
5083     disp($reg);  // Stack Offset
5084   %}
5085 %}
5086 
5087 operand stackSlotI(sRegI reg)
5088 %{
5089   constraint(ALLOC_IN_RC(stack_slots));
5090   // No match rule because this operand is only generated in matching
5091 
5092   format %{ "[$reg]" %}
5093   interface(MEMORY_INTER) %{
5094     base(0x4);   // RSP
5095     index(0x4);  // No Index
5096     scale(0x0);  // No Scale
5097     disp($reg);  // Stack Offset
5098   %}
5099 %}
5100 
5101 operand stackSlotF(sRegF reg)
5102 %{
5103   constraint(ALLOC_IN_RC(stack_slots));
5104   // No match rule because this operand is only generated in matching
5105 
5106   format %{ "[$reg]" %}
5107   interface(MEMORY_INTER) %{
5108     base(0x4);   // RSP
5109     index(0x4);  // No Index
5110     scale(0x0);  // No Scale
5111     disp($reg);  // Stack Offset
5112   %}
5113 %}
5114 
5115 operand stackSlotD(sRegD reg)
5116 %{
5117   constraint(ALLOC_IN_RC(stack_slots));
5118   // No match rule because this operand is only generated in matching
5119 
5120   format %{ "[$reg]" %}
5121   interface(MEMORY_INTER) %{
5122     base(0x4);   // RSP
5123     index(0x4);  // No Index
5124     scale(0x0);  // No Scale
5125     disp($reg);  // Stack Offset
5126   %}
5127 %}
5128 operand stackSlotL(sRegL reg)
5129 %{
5130   constraint(ALLOC_IN_RC(stack_slots));
5131   // No match rule because this operand is only generated in matching
5132 
5133   format %{ "[$reg]" %}
5134   interface(MEMORY_INTER) %{
5135     base(0x4);   // RSP
5136     index(0x4);  // No Index
5137     scale(0x0);  // No Scale
5138     disp($reg);  // Stack Offset
5139   %}
5140 %}
5141 
5142 //----------Conditional Branch Operands----------------------------------------
5143 // Comparison Op  - This is the operation of the comparison, and is limited to
5144 //                  the following set of codes:
5145 //                  L (<), LE (<=), G (>), GE (>=), E (==), NE (!=)
5146 //
5147 // Other attributes of the comparison, such as unsignedness, are specified
5148 // by the comparison instruction that sets a condition code flags register.
5149 // That result is represented by a flags operand whose subtype is appropriate
5150 // to the unsignedness (etc.) of the comparison.
5151 //
5152 // Later, the instruction which matches both the Comparison Op (a Bool) and
5153 // the flags (produced by the Cmp) specifies the coding of the comparison op
5154 // by matching a specific subtype of Bool operand below, such as cmpOpU.
5155 
5156 // Comparision Code
5157 operand cmpOp()
5158 %{
5159   match(Bool);
5160 
5161   format %{ "" %}
5162   interface(COND_INTER) %{
5163     equal(0x4, "e");
5164     not_equal(0x5, "ne");
5165     less(0xC, "l");
5166     greater_equal(0xD, "ge");
5167     less_equal(0xE, "le");
5168     greater(0xF, "g");
5169   %}
5170 %}
5171 
5172 // Comparison Code, unsigned compare.  Used by FP also, with
5173 // C2 (unordered) turned into GT or LT already.  The other bits
5174 // C0 and C3 are turned into Carry & Zero flags.
5175 operand cmpOpU()
5176 %{
5177   match(Bool);
5178 
5179   format %{ "" %}
5180   interface(COND_INTER) %{
5181     equal(0x4, "e");
5182     not_equal(0x5, "ne");
5183     less(0x2, "b");
5184     greater_equal(0x3, "nb");
5185     less_equal(0x6, "be");
5186     greater(0x7, "nbe");
5187   %}
5188 %}
5189 
5190 
5191 // Floating comparisons that don't require any fixup for the unordered case
5192 operand cmpOpUCF() %{
5193   match(Bool);
5194   predicate(n->as_Bool()->_test._test == BoolTest::lt ||
5195             n->as_Bool()->_test._test == BoolTest::ge ||
5196             n->as_Bool()->_test._test == BoolTest::le ||
5197             n->as_Bool()->_test._test == BoolTest::gt);
5198   format %{ "" %}
5199   interface(COND_INTER) %{
5200     equal(0x4, "e");
5201     not_equal(0x5, "ne");
5202     less(0x2, "b");
5203     greater_equal(0x3, "nb");
5204     less_equal(0x6, "be");
5205     greater(0x7, "nbe");
5206   %}
5207 %}
5208 
5209 
5210 // Floating comparisons that can be fixed up with extra conditional jumps
5211 operand cmpOpUCF2() %{
5212   match(Bool);
5213   predicate(n->as_Bool()->_test._test == BoolTest::ne ||
5214             n->as_Bool()->_test._test == BoolTest::eq);
5215   format %{ "" %}
5216   interface(COND_INTER) %{
5217     equal(0x4, "e");
5218     not_equal(0x5, "ne");
5219     less(0x2, "b");
5220     greater_equal(0x3, "nb");
5221     less_equal(0x6, "be");
5222     greater(0x7, "nbe");
5223   %}
5224 %}
5225 
5226 
5227 //----------OPERAND CLASSES----------------------------------------------------
5228 // Operand Classes are groups of operands that are used as to simplify
5229 // instruction definitions by not requiring the AD writer to specify separate
5230 // instructions for every form of operand when the instruction accepts
5231 // multiple operand types with the same basic encoding and format.  The classic
5232 // case of this is memory operands.
5233 
5234 opclass memory(indirect, indOffset8, indOffset32, indIndexOffset, indIndex,
5235                indIndexScale, indIndexScaleOffset, indPosIndexScaleOffset,
5236                indCompressedOopOffset,
5237                indirectNarrow, indOffset8Narrow, indOffset32Narrow,
5238                indIndexOffsetNarrow, indIndexNarrow, indIndexScaleNarrow,
5239                indIndexScaleOffsetNarrow, indPosIndexScaleOffsetNarrow);
5240 
5241 //----------PIPELINE-----------------------------------------------------------
5242 // Rules which define the behavior of the target architectures pipeline.
5243 pipeline %{
5244 
5245 //----------ATTRIBUTES---------------------------------------------------------
5246 attributes %{
5247   variable_size_instructions;        // Fixed size instructions
5248   max_instructions_per_bundle = 3;   // Up to 3 instructions per bundle
5249   instruction_unit_size = 1;         // An instruction is 1 bytes long
5250   instruction_fetch_unit_size = 16;  // The processor fetches one line
5251   instruction_fetch_units = 1;       // of 16 bytes
5252 
5253   // List of nop instructions
5254   nops( MachNop );
5255 %}
5256 
5257 //----------RESOURCES----------------------------------------------------------
5258 // Resources are the functional units available to the machine
5259 
5260 // Generic P2/P3 pipeline
5261 // 3 decoders, only D0 handles big operands; a "bundle" is the limit of
5262 // 3 instructions decoded per cycle.
5263 // 2 load/store ops per cycle, 1 branch, 1 FPU,
5264 // 3 ALU op, only ALU0 handles mul instructions.
5265 resources( D0, D1, D2, DECODE = D0 | D1 | D2,
5266            MS0, MS1, MS2, MEM = MS0 | MS1 | MS2,
5267            BR, FPU,
5268            ALU0, ALU1, ALU2, ALU = ALU0 | ALU1 | ALU2);
5269 
5270 //----------PIPELINE DESCRIPTION-----------------------------------------------
5271 // Pipeline Description specifies the stages in the machine's pipeline
5272 
5273 // Generic P2/P3 pipeline
5274 pipe_desc(S0, S1, S2, S3, S4, S5);
5275 
5276 //----------PIPELINE CLASSES---------------------------------------------------
5277 // Pipeline Classes describe the stages in which input and output are
5278 // referenced by the hardware pipeline.
5279 
5280 // Naming convention: ialu or fpu
5281 // Then: _reg
5282 // Then: _reg if there is a 2nd register
5283 // Then: _long if it's a pair of instructions implementing a long
5284 // Then: _fat if it requires the big decoder
5285 //   Or: _mem if it requires the big decoder and a memory unit.
5286 
5287 // Integer ALU reg operation
5288 pipe_class ialu_reg(rRegI dst)
5289 %{
5290     single_instruction;
5291     dst    : S4(write);
5292     dst    : S3(read);
5293     DECODE : S0;        // any decoder
5294     ALU    : S3;        // any alu
5295 %}
5296 
5297 // Long ALU reg operation
5298 pipe_class ialu_reg_long(rRegL dst)
5299 %{
5300     instruction_count(2);
5301     dst    : S4(write);
5302     dst    : S3(read);
5303     DECODE : S0(2);     // any 2 decoders
5304     ALU    : S3(2);     // both alus
5305 %}
5306 
5307 // Integer ALU reg operation using big decoder
5308 pipe_class ialu_reg_fat(rRegI dst)
5309 %{
5310     single_instruction;
5311     dst    : S4(write);
5312     dst    : S3(read);
5313     D0     : S0;        // big decoder only
5314     ALU    : S3;        // any alu
5315 %}
5316 
5317 // Long ALU reg operation using big decoder
5318 pipe_class ialu_reg_long_fat(rRegL dst)
5319 %{
5320     instruction_count(2);
5321     dst    : S4(write);
5322     dst    : S3(read);
5323     D0     : S0(2);     // big decoder only; twice
5324     ALU    : S3(2);     // any 2 alus
5325 %}
5326 
5327 // Integer ALU reg-reg operation
5328 pipe_class ialu_reg_reg(rRegI dst, rRegI src)
5329 %{
5330     single_instruction;
5331     dst    : S4(write);
5332     src    : S3(read);
5333     DECODE : S0;        // any decoder
5334     ALU    : S3;        // any alu
5335 %}
5336 
5337 // Long ALU reg-reg operation
5338 pipe_class ialu_reg_reg_long(rRegL dst, rRegL src)
5339 %{
5340     instruction_count(2);
5341     dst    : S4(write);
5342     src    : S3(read);
5343     DECODE : S0(2);     // any 2 decoders
5344     ALU    : S3(2);     // both alus
5345 %}
5346 
5347 // Integer ALU reg-reg operation
5348 pipe_class ialu_reg_reg_fat(rRegI dst, memory src)
5349 %{
5350     single_instruction;
5351     dst    : S4(write);
5352     src    : S3(read);
5353     D0     : S0;        // big decoder only
5354     ALU    : S3;        // any alu
5355 %}
5356 
5357 // Long ALU reg-reg operation
5358 pipe_class ialu_reg_reg_long_fat(rRegL dst, rRegL src)
5359 %{
5360     instruction_count(2);
5361     dst    : S4(write);
5362     src    : S3(read);
5363     D0     : S0(2);     // big decoder only; twice
5364     ALU    : S3(2);     // both alus
5365 %}
5366 
5367 // Integer ALU reg-mem operation
5368 pipe_class ialu_reg_mem(rRegI dst, memory mem)
5369 %{
5370     single_instruction;
5371     dst    : S5(write);
5372     mem    : S3(read);
5373     D0     : S0;        // big decoder only
5374     ALU    : S4;        // any alu
5375     MEM    : S3;        // any mem
5376 %}
5377 
5378 // Integer mem operation (prefetch)
5379 pipe_class ialu_mem(memory mem)
5380 %{
5381     single_instruction;
5382     mem    : S3(read);
5383     D0     : S0;        // big decoder only
5384     MEM    : S3;        // any mem
5385 %}
5386 
5387 // Integer Store to Memory
5388 pipe_class ialu_mem_reg(memory mem, rRegI src)
5389 %{
5390     single_instruction;
5391     mem    : S3(read);
5392     src    : S5(read);
5393     D0     : S0;        // big decoder only
5394     ALU    : S4;        // any alu
5395     MEM    : S3;
5396 %}
5397 
5398 // // Long Store to Memory
5399 // pipe_class ialu_mem_long_reg(memory mem, rRegL src)
5400 // %{
5401 //     instruction_count(2);
5402 //     mem    : S3(read);
5403 //     src    : S5(read);
5404 //     D0     : S0(2);          // big decoder only; twice
5405 //     ALU    : S4(2);     // any 2 alus
5406 //     MEM    : S3(2);  // Both mems
5407 // %}
5408 
5409 // Integer Store to Memory
5410 pipe_class ialu_mem_imm(memory mem)
5411 %{
5412     single_instruction;
5413     mem    : S3(read);
5414     D0     : S0;        // big decoder only
5415     ALU    : S4;        // any alu
5416     MEM    : S3;
5417 %}
5418 
5419 // Integer ALU0 reg-reg operation
5420 pipe_class ialu_reg_reg_alu0(rRegI dst, rRegI src)
5421 %{
5422     single_instruction;
5423     dst    : S4(write);
5424     src    : S3(read);
5425     D0     : S0;        // Big decoder only
5426     ALU0   : S3;        // only alu0
5427 %}
5428 
5429 // Integer ALU0 reg-mem operation
5430 pipe_class ialu_reg_mem_alu0(rRegI dst, memory mem)
5431 %{
5432     single_instruction;
5433     dst    : S5(write);
5434     mem    : S3(read);
5435     D0     : S0;        // big decoder only
5436     ALU0   : S4;        // ALU0 only
5437     MEM    : S3;        // any mem
5438 %}
5439 
5440 // Integer ALU reg-reg operation
5441 pipe_class ialu_cr_reg_reg(rFlagsReg cr, rRegI src1, rRegI src2)
5442 %{
5443     single_instruction;
5444     cr     : S4(write);
5445     src1   : S3(read);
5446     src2   : S3(read);
5447     DECODE : S0;        // any decoder
5448     ALU    : S3;        // any alu
5449 %}
5450 
5451 // Integer ALU reg-imm operation
5452 pipe_class ialu_cr_reg_imm(rFlagsReg cr, rRegI src1)
5453 %{
5454     single_instruction;
5455     cr     : S4(write);
5456     src1   : S3(read);
5457     DECODE : S0;        // any decoder
5458     ALU    : S3;        // any alu
5459 %}
5460 
5461 // Integer ALU reg-mem operation
5462 pipe_class ialu_cr_reg_mem(rFlagsReg cr, rRegI src1, memory src2)
5463 %{
5464     single_instruction;
5465     cr     : S4(write);
5466     src1   : S3(read);
5467     src2   : S3(read);
5468     D0     : S0;        // big decoder only
5469     ALU    : S4;        // any alu
5470     MEM    : S3;
5471 %}
5472 
5473 // Conditional move reg-reg
5474 pipe_class pipe_cmplt( rRegI p, rRegI q, rRegI y)
5475 %{
5476     instruction_count(4);
5477     y      : S4(read);
5478     q      : S3(read);
5479     p      : S3(read);
5480     DECODE : S0(4);     // any decoder
5481 %}
5482 
5483 // Conditional move reg-reg
5484 pipe_class pipe_cmov_reg( rRegI dst, rRegI src, rFlagsReg cr)
5485 %{
5486     single_instruction;
5487     dst    : S4(write);
5488     src    : S3(read);
5489     cr     : S3(read);
5490     DECODE : S0;        // any decoder
5491 %}
5492 
5493 // Conditional move reg-mem
5494 pipe_class pipe_cmov_mem( rFlagsReg cr, rRegI dst, memory src)
5495 %{
5496     single_instruction;
5497     dst    : S4(write);
5498     src    : S3(read);
5499     cr     : S3(read);
5500     DECODE : S0;        // any decoder
5501     MEM    : S3;
5502 %}
5503 
5504 // Conditional move reg-reg long
5505 pipe_class pipe_cmov_reg_long( rFlagsReg cr, rRegL dst, rRegL src)
5506 %{
5507     single_instruction;
5508     dst    : S4(write);
5509     src    : S3(read);
5510     cr     : S3(read);
5511     DECODE : S0(2);     // any 2 decoders
5512 %}
5513 
5514 // XXX
5515 // // Conditional move double reg-reg
5516 // pipe_class pipe_cmovD_reg( rFlagsReg cr, regDPR1 dst, regD src)
5517 // %{
5518 //     single_instruction;
5519 //     dst    : S4(write);
5520 //     src    : S3(read);
5521 //     cr     : S3(read);
5522 //     DECODE : S0;     // any decoder
5523 // %}
5524 
5525 // Float reg-reg operation
5526 pipe_class fpu_reg(regD dst)
5527 %{
5528     instruction_count(2);
5529     dst    : S3(read);
5530     DECODE : S0(2);     // any 2 decoders
5531     FPU    : S3;
5532 %}
5533 
5534 // Float reg-reg operation
5535 pipe_class fpu_reg_reg(regD dst, regD src)
5536 %{
5537     instruction_count(2);
5538     dst    : S4(write);
5539     src    : S3(read);
5540     DECODE : S0(2);     // any 2 decoders
5541     FPU    : S3;
5542 %}
5543 
5544 // Float reg-reg operation
5545 pipe_class fpu_reg_reg_reg(regD dst, regD src1, regD src2)
5546 %{
5547     instruction_count(3);
5548     dst    : S4(write);
5549     src1   : S3(read);
5550     src2   : S3(read);
5551     DECODE : S0(3);     // any 3 decoders
5552     FPU    : S3(2);
5553 %}
5554 
5555 // Float reg-reg operation
5556 pipe_class fpu_reg_reg_reg_reg(regD dst, regD src1, regD src2, regD src3)
5557 %{
5558     instruction_count(4);
5559     dst    : S4(write);
5560     src1   : S3(read);
5561     src2   : S3(read);
5562     src3   : S3(read);
5563     DECODE : S0(4);     // any 3 decoders
5564     FPU    : S3(2);
5565 %}
5566 
5567 // Float reg-reg operation
5568 pipe_class fpu_reg_mem_reg_reg(regD dst, memory src1, regD src2, regD src3)
5569 %{
5570     instruction_count(4);
5571     dst    : S4(write);
5572     src1   : S3(read);
5573     src2   : S3(read);
5574     src3   : S3(read);
5575     DECODE : S1(3);     // any 3 decoders
5576     D0     : S0;        // Big decoder only
5577     FPU    : S3(2);
5578     MEM    : S3;
5579 %}
5580 
5581 // Float reg-mem operation
5582 pipe_class fpu_reg_mem(regD dst, memory mem)
5583 %{
5584     instruction_count(2);
5585     dst    : S5(write);
5586     mem    : S3(read);
5587     D0     : S0;        // big decoder only
5588     DECODE : S1;        // any decoder for FPU POP
5589     FPU    : S4;
5590     MEM    : S3;        // any mem
5591 %}
5592 
5593 // Float reg-mem operation
5594 pipe_class fpu_reg_reg_mem(regD dst, regD src1, memory mem)
5595 %{
5596     instruction_count(3);
5597     dst    : S5(write);
5598     src1   : S3(read);
5599     mem    : S3(read);
5600     D0     : S0;        // big decoder only
5601     DECODE : S1(2);     // any decoder for FPU POP
5602     FPU    : S4;
5603     MEM    : S3;        // any mem
5604 %}
5605 
5606 // Float mem-reg operation
5607 pipe_class fpu_mem_reg(memory mem, regD src)
5608 %{
5609     instruction_count(2);
5610     src    : S5(read);
5611     mem    : S3(read);
5612     DECODE : S0;        // any decoder for FPU PUSH
5613     D0     : S1;        // big decoder only
5614     FPU    : S4;
5615     MEM    : S3;        // any mem
5616 %}
5617 
5618 pipe_class fpu_mem_reg_reg(memory mem, regD src1, regD src2)
5619 %{
5620     instruction_count(3);
5621     src1   : S3(read);
5622     src2   : S3(read);
5623     mem    : S3(read);
5624     DECODE : S0(2);     // any decoder for FPU PUSH
5625     D0     : S1;        // big decoder only
5626     FPU    : S4;
5627     MEM    : S3;        // any mem
5628 %}
5629 
5630 pipe_class fpu_mem_reg_mem(memory mem, regD src1, memory src2)
5631 %{
5632     instruction_count(3);
5633     src1   : S3(read);
5634     src2   : S3(read);
5635     mem    : S4(read);
5636     DECODE : S0;        // any decoder for FPU PUSH
5637     D0     : S0(2);     // big decoder only
5638     FPU    : S4;
5639     MEM    : S3(2);     // any mem
5640 %}
5641 
5642 pipe_class fpu_mem_mem(memory dst, memory src1)
5643 %{
5644     instruction_count(2);
5645     src1   : S3(read);
5646     dst    : S4(read);
5647     D0     : S0(2);     // big decoder only
5648     MEM    : S3(2);     // any mem
5649 %}
5650 
5651 pipe_class fpu_mem_mem_mem(memory dst, memory src1, memory src2)
5652 %{
5653     instruction_count(3);
5654     src1   : S3(read);
5655     src2   : S3(read);
5656     dst    : S4(read);
5657     D0     : S0(3);     // big decoder only
5658     FPU    : S4;
5659     MEM    : S3(3);     // any mem
5660 %}
5661 
5662 pipe_class fpu_mem_reg_con(memory mem, regD src1)
5663 %{
5664     instruction_count(3);
5665     src1   : S4(read);
5666     mem    : S4(read);
5667     DECODE : S0;        // any decoder for FPU PUSH
5668     D0     : S0(2);     // big decoder only
5669     FPU    : S4;
5670     MEM    : S3(2);     // any mem
5671 %}
5672 
5673 // Float load constant
5674 pipe_class fpu_reg_con(regD dst)
5675 %{
5676     instruction_count(2);
5677     dst    : S5(write);
5678     D0     : S0;        // big decoder only for the load
5679     DECODE : S1;        // any decoder for FPU POP
5680     FPU    : S4;
5681     MEM    : S3;        // any mem
5682 %}
5683 
5684 // Float load constant
5685 pipe_class fpu_reg_reg_con(regD dst, regD src)
5686 %{
5687     instruction_count(3);
5688     dst    : S5(write);
5689     src    : S3(read);
5690     D0     : S0;        // big decoder only for the load
5691     DECODE : S1(2);     // any decoder for FPU POP
5692     FPU    : S4;
5693     MEM    : S3;        // any mem
5694 %}
5695 
5696 // UnConditional branch
5697 pipe_class pipe_jmp(label labl)
5698 %{
5699     single_instruction;
5700     BR   : S3;
5701 %}
5702 
5703 // Conditional branch
5704 pipe_class pipe_jcc(cmpOp cmp, rFlagsReg cr, label labl)
5705 %{
5706     single_instruction;
5707     cr    : S1(read);
5708     BR    : S3;
5709 %}
5710 
5711 // Allocation idiom
5712 pipe_class pipe_cmpxchg(rRegP dst, rRegP heap_ptr)
5713 %{
5714     instruction_count(1); force_serialization;
5715     fixed_latency(6);
5716     heap_ptr : S3(read);
5717     DECODE   : S0(3);
5718     D0       : S2;
5719     MEM      : S3;
5720     ALU      : S3(2);
5721     dst      : S5(write);
5722     BR       : S5;
5723 %}
5724 
5725 // Generic big/slow expanded idiom
5726 pipe_class pipe_slow()
5727 %{
5728     instruction_count(10); multiple_bundles; force_serialization;
5729     fixed_latency(100);
5730     D0  : S0(2);
5731     MEM : S3(2);
5732 %}
5733 
5734 // The real do-nothing guy
5735 pipe_class empty()
5736 %{
5737     instruction_count(0);
5738 %}
5739 
5740 // Define the class for the Nop node
5741 define
5742 %{
5743    MachNop = empty;
5744 %}
5745 
5746 %}
5747 
5748 //----------INSTRUCTIONS-------------------------------------------------------
5749 //
5750 // match      -- States which machine-independent subtree may be replaced
5751 //               by this instruction.
5752 // ins_cost   -- The estimated cost of this instruction is used by instruction
5753 //               selection to identify a minimum cost tree of machine
5754 //               instructions that matches a tree of machine-independent
5755 //               instructions.
5756 // format     -- A string providing the disassembly for this instruction.
5757 //               The value of an instruction's operand may be inserted
5758 //               by referring to it with a '$' prefix.
5759 // opcode     -- Three instruction opcodes may be provided.  These are referred
5760 //               to within an encode class as $primary, $secondary, and $tertiary
5761 //               rrspectively.  The primary opcode is commonly used to
5762 //               indicate the type of machine instruction, while secondary
5763 //               and tertiary are often used for prefix options or addressing
5764 //               modes.
5765 // ins_encode -- A list of encode classes with parameters. The encode class
5766 //               name must have been defined in an 'enc_class' specification
5767 //               in the encode section of the architecture description.
5768 
5769 
5770 //----------Load/Store/Move Instructions---------------------------------------
5771 //----------Load Instructions--------------------------------------------------
5772 
5773 // Load Byte (8 bit signed)
5774 instruct loadB(rRegI dst, memory mem)
5775 %{
5776   match(Set dst (LoadB mem));
5777 
5778   ins_cost(125);
5779   format %{ "movsbl  $dst, $mem\t# byte" %}
5780 
5781   ins_encode %{
5782     __ movsbl($dst$$Register, $mem$$Address);
5783   %}
5784 
5785   ins_pipe(ialu_reg_mem);
5786 %}
5787 
5788 // Load Byte (8 bit signed) into Long Register
5789 instruct loadB2L(rRegL dst, memory mem)
5790 %{
5791   match(Set dst (ConvI2L (LoadB mem)));
5792 
5793   ins_cost(125);
5794   format %{ "movsbq  $dst, $mem\t# byte -> long" %}
5795 
5796   ins_encode %{
5797     __ movsbq($dst$$Register, $mem$$Address);
5798   %}
5799 
5800   ins_pipe(ialu_reg_mem);
5801 %}
5802 
5803 // Load Unsigned Byte (8 bit UNsigned)
5804 instruct loadUB(rRegI dst, memory mem)
5805 %{
5806   match(Set dst (LoadUB mem));
5807 
5808   ins_cost(125);
5809   format %{ "movzbl  $dst, $mem\t# ubyte" %}
5810 
5811   ins_encode %{
5812     __ movzbl($dst$$Register, $mem$$Address);
5813   %}
5814 
5815   ins_pipe(ialu_reg_mem);
5816 %}
5817 
5818 // Load Unsigned Byte (8 bit UNsigned) into Long Register
5819 instruct loadUB2L(rRegL dst, memory mem)
5820 %{
5821   match(Set dst (ConvI2L (LoadUB mem)));
5822 
5823   ins_cost(125);
5824   format %{ "movzbq  $dst, $mem\t# ubyte -> long" %}
5825 
5826   ins_encode %{
5827     __ movzbq($dst$$Register, $mem$$Address);
5828   %}
5829 
5830   ins_pipe(ialu_reg_mem);
5831 %}
5832 
5833 // Load Unsigned Byte (8 bit UNsigned) with a 8-bit mask into Long Register
5834 instruct loadUB2L_immI8(rRegL dst, memory mem, immI8 mask, rFlagsReg cr) %{
5835   match(Set dst (ConvI2L (AndI (LoadUB mem) mask)));
5836   effect(KILL cr);
5837 
5838   format %{ "movzbq  $dst, $mem\t# ubyte & 8-bit mask -> long\n\t"
5839             "andl    $dst, $mask" %}
5840   ins_encode %{
5841     Register Rdst = $dst$$Register;
5842     __ movzbq(Rdst, $mem$$Address);
5843     __ andl(Rdst, $mask$$constant);
5844   %}
5845   ins_pipe(ialu_reg_mem);
5846 %}
5847 
5848 // Load Short (16 bit signed)
5849 instruct loadS(rRegI dst, memory mem)
5850 %{
5851   match(Set dst (LoadS mem));
5852 
5853   ins_cost(125);
5854   format %{ "movswl $dst, $mem\t# short" %}
5855 
5856   ins_encode %{
5857     __ movswl($dst$$Register, $mem$$Address);
5858   %}
5859 
5860   ins_pipe(ialu_reg_mem);
5861 %}
5862 
5863 // Load Short (16 bit signed) to Byte (8 bit signed)
5864 instruct loadS2B(rRegI dst, memory mem, immI_24 twentyfour) %{
5865   match(Set dst (RShiftI (LShiftI (LoadS mem) twentyfour) twentyfour));
5866 
5867   ins_cost(125);
5868   format %{ "movsbl $dst, $mem\t# short -> byte" %}
5869   ins_encode %{
5870     __ movsbl($dst$$Register, $mem$$Address);
5871   %}
5872   ins_pipe(ialu_reg_mem);
5873 %}
5874 
5875 // Load Short (16 bit signed) into Long Register
5876 instruct loadS2L(rRegL dst, memory mem)
5877 %{
5878   match(Set dst (ConvI2L (LoadS mem)));
5879 
5880   ins_cost(125);
5881   format %{ "movswq $dst, $mem\t# short -> long" %}
5882 
5883   ins_encode %{
5884     __ movswq($dst$$Register, $mem$$Address);
5885   %}
5886 
5887   ins_pipe(ialu_reg_mem);
5888 %}
5889 
5890 // Load Unsigned Short/Char (16 bit UNsigned)
5891 instruct loadUS(rRegI dst, memory mem)
5892 %{
5893   match(Set dst (LoadUS mem));
5894 
5895   ins_cost(125);
5896   format %{ "movzwl  $dst, $mem\t# ushort/char" %}
5897 
5898   ins_encode %{
5899     __ movzwl($dst$$Register, $mem$$Address);
5900   %}
5901 
5902   ins_pipe(ialu_reg_mem);
5903 %}
5904 
5905 // Load Unsigned Short/Char (16 bit UNsigned) to Byte (8 bit signed)
5906 instruct loadUS2B(rRegI dst, memory mem, immI_24 twentyfour) %{
5907   match(Set dst (RShiftI (LShiftI (LoadUS mem) twentyfour) twentyfour));
5908 
5909   ins_cost(125);
5910   format %{ "movsbl $dst, $mem\t# ushort -> byte" %}
5911   ins_encode %{
5912     __ movsbl($dst$$Register, $mem$$Address);
5913   %}
5914   ins_pipe(ialu_reg_mem);
5915 %}
5916 
5917 // Load Unsigned Short/Char (16 bit UNsigned) into Long Register
5918 instruct loadUS2L(rRegL dst, memory mem)
5919 %{
5920   match(Set dst (ConvI2L (LoadUS mem)));
5921 
5922   ins_cost(125);
5923   format %{ "movzwq  $dst, $mem\t# ushort/char -> long" %}
5924 
5925   ins_encode %{
5926     __ movzwq($dst$$Register, $mem$$Address);
5927   %}
5928 
5929   ins_pipe(ialu_reg_mem);
5930 %}
5931 
5932 // Load Unsigned Short/Char (16 bit UNsigned) with mask 0xFF into Long Register
5933 instruct loadUS2L_immI_255(rRegL dst, memory mem, immI_255 mask) %{
5934   match(Set dst (ConvI2L (AndI (LoadUS mem) mask)));
5935 
5936   format %{ "movzbq  $dst, $mem\t# ushort/char & 0xFF -> long" %}
5937   ins_encode %{
5938     __ movzbq($dst$$Register, $mem$$Address);
5939   %}
5940   ins_pipe(ialu_reg_mem);
5941 %}
5942 
5943 // Load Unsigned Short/Char (16 bit UNsigned) with mask into Long Register
5944 instruct loadUS2L_immI16(rRegL dst, memory mem, immI16 mask, rFlagsReg cr) %{
5945   match(Set dst (ConvI2L (AndI (LoadUS mem) mask)));
5946   effect(KILL cr);
5947 
5948   format %{ "movzwq  $dst, $mem\t# ushort/char & 16-bit mask -> long\n\t"
5949             "andl    $dst, $mask" %}
5950   ins_encode %{
5951     Register Rdst = $dst$$Register;
5952     __ movzwq(Rdst, $mem$$Address);
5953     __ andl(Rdst, $mask$$constant);
5954   %}
5955   ins_pipe(ialu_reg_mem);
5956 %}
5957 
5958 // Load Integer
5959 instruct loadI(rRegI dst, memory mem)
5960 %{
5961   match(Set dst (LoadI mem));
5962 
5963   ins_cost(125);
5964   format %{ "movl    $dst, $mem\t# int" %}
5965 
5966   ins_encode %{
5967     __ movl($dst$$Register, $mem$$Address);
5968   %}
5969 
5970   ins_pipe(ialu_reg_mem);
5971 %}
5972 
5973 // Load Integer (32 bit signed) to Byte (8 bit signed)
5974 instruct loadI2B(rRegI dst, memory mem, immI_24 twentyfour) %{
5975   match(Set dst (RShiftI (LShiftI (LoadI mem) twentyfour) twentyfour));
5976 
5977   ins_cost(125);
5978   format %{ "movsbl  $dst, $mem\t# int -> byte" %}
5979   ins_encode %{
5980     __ movsbl($dst$$Register, $mem$$Address);
5981   %}
5982   ins_pipe(ialu_reg_mem);
5983 %}
5984 
5985 // Load Integer (32 bit signed) to Unsigned Byte (8 bit UNsigned)
5986 instruct loadI2UB(rRegI dst, memory mem, immI_255 mask) %{
5987   match(Set dst (AndI (LoadI mem) mask));
5988 
5989   ins_cost(125);
5990   format %{ "movzbl  $dst, $mem\t# int -> ubyte" %}
5991   ins_encode %{
5992     __ movzbl($dst$$Register, $mem$$Address);
5993   %}
5994   ins_pipe(ialu_reg_mem);
5995 %}
5996 
5997 // Load Integer (32 bit signed) to Short (16 bit signed)
5998 instruct loadI2S(rRegI dst, memory mem, immI_16 sixteen) %{
5999   match(Set dst (RShiftI (LShiftI (LoadI mem) sixteen) sixteen));
6000 
6001   ins_cost(125);
6002   format %{ "movswl  $dst, $mem\t# int -> short" %}
6003   ins_encode %{
6004     __ movswl($dst$$Register, $mem$$Address);
6005   %}
6006   ins_pipe(ialu_reg_mem);
6007 %}
6008 
6009 // Load Integer (32 bit signed) to Unsigned Short/Char (16 bit UNsigned)
6010 instruct loadI2US(rRegI dst, memory mem, immI_65535 mask) %{
6011   match(Set dst (AndI (LoadI mem) mask));
6012 
6013   ins_cost(125);
6014   format %{ "movzwl  $dst, $mem\t# int -> ushort/char" %}
6015   ins_encode %{
6016     __ movzwl($dst$$Register, $mem$$Address);
6017   %}
6018   ins_pipe(ialu_reg_mem);
6019 %}
6020 
6021 // Load Integer into Long Register
6022 instruct loadI2L(rRegL dst, memory mem)
6023 %{
6024   match(Set dst (ConvI2L (LoadI mem)));
6025 
6026   ins_cost(125);
6027   format %{ "movslq  $dst, $mem\t# int -> long" %}
6028 
6029   ins_encode %{
6030     __ movslq($dst$$Register, $mem$$Address);
6031   %}
6032 
6033   ins_pipe(ialu_reg_mem);
6034 %}
6035 
6036 // Load Integer with mask 0xFF into Long Register
6037 instruct loadI2L_immI_255(rRegL dst, memory mem, immI_255 mask) %{
6038   match(Set dst (ConvI2L (AndI (LoadI mem) mask)));
6039 
6040   format %{ "movzbq  $dst, $mem\t# int & 0xFF -> long" %}
6041   ins_encode %{
6042     __ movzbq($dst$$Register, $mem$$Address);
6043   %}
6044   ins_pipe(ialu_reg_mem);
6045 %}
6046 
6047 // Load Integer with mask 0xFFFF into Long Register
6048 instruct loadI2L_immI_65535(rRegL dst, memory mem, immI_65535 mask) %{
6049   match(Set dst (ConvI2L (AndI (LoadI mem) mask)));
6050 
6051   format %{ "movzwq  $dst, $mem\t# int & 0xFFFF -> long" %}
6052   ins_encode %{
6053     __ movzwq($dst$$Register, $mem$$Address);
6054   %}
6055   ins_pipe(ialu_reg_mem);
6056 %}
6057 
6058 // Load Integer with a 32-bit mask into Long Register
6059 instruct loadI2L_immI(rRegL dst, memory mem, immI mask, rFlagsReg cr) %{
6060   match(Set dst (ConvI2L (AndI (LoadI mem) mask)));
6061   effect(KILL cr);
6062 
6063   format %{ "movl    $dst, $mem\t# int & 32-bit mask -> long\n\t"
6064             "andl    $dst, $mask" %}
6065   ins_encode %{
6066     Register Rdst = $dst$$Register;
6067     __ movl(Rdst, $mem$$Address);
6068     __ andl(Rdst, $mask$$constant);
6069   %}
6070   ins_pipe(ialu_reg_mem);
6071 %}
6072 
6073 // Load Unsigned Integer into Long Register
6074 instruct loadUI2L(rRegL dst, memory mem)
6075 %{
6076   match(Set dst (LoadUI2L mem));
6077 
6078   ins_cost(125);
6079   format %{ "movl    $dst, $mem\t# uint -> long" %}
6080 
6081   ins_encode %{
6082     __ movl($dst$$Register, $mem$$Address);
6083   %}
6084 
6085   ins_pipe(ialu_reg_mem);
6086 %}
6087 
6088 // Load Long
6089 instruct loadL(rRegL dst, memory mem)
6090 %{
6091   match(Set dst (LoadL mem));
6092 
6093   ins_cost(125);
6094   format %{ "movq    $dst, $mem\t# long" %}
6095 
6096   ins_encode %{
6097     __ movq($dst$$Register, $mem$$Address);
6098   %}
6099 
6100   ins_pipe(ialu_reg_mem); // XXX
6101 %}
6102 
6103 // Load Range
6104 instruct loadRange(rRegI dst, memory mem)
6105 %{
6106   match(Set dst (LoadRange mem));
6107 
6108   ins_cost(125); // XXX
6109   format %{ "movl    $dst, $mem\t# range" %}
6110   opcode(0x8B);
6111   ins_encode(REX_reg_mem(dst, mem), OpcP, reg_mem(dst, mem));
6112   ins_pipe(ialu_reg_mem);
6113 %}
6114 
6115 // Load Pointer
6116 instruct loadP(rRegP dst, memory mem)
6117 %{
6118   match(Set dst (LoadP mem));
6119 
6120   ins_cost(125); // XXX
6121   format %{ "movq    $dst, $mem\t# ptr" %}
6122   opcode(0x8B);
6123   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
6124   ins_pipe(ialu_reg_mem); // XXX
6125 %}
6126 
6127 // Load Compressed Pointer
6128 instruct loadN(rRegN dst, memory mem)
6129 %{
6130    match(Set dst (LoadN mem));
6131 
6132    ins_cost(125); // XXX
6133    format %{ "movl    $dst, $mem\t# compressed ptr" %}
6134    ins_encode %{
6135      __ movl($dst$$Register, $mem$$Address);
6136    %}
6137    ins_pipe(ialu_reg_mem); // XXX
6138 %}
6139 
6140 
6141 // Load Klass Pointer
6142 instruct loadKlass(rRegP dst, memory mem)
6143 %{
6144   match(Set dst (LoadKlass mem));
6145 
6146   ins_cost(125); // XXX
6147   format %{ "movq    $dst, $mem\t# class" %}
6148   opcode(0x8B);
6149   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
6150   ins_pipe(ialu_reg_mem); // XXX
6151 %}
6152 
6153 // Load narrow Klass Pointer
6154 instruct loadNKlass(rRegN dst, memory mem)
6155 %{
6156   match(Set dst (LoadNKlass mem));
6157 
6158   ins_cost(125); // XXX
6159   format %{ "movl    $dst, $mem\t# compressed klass ptr" %}
6160   ins_encode %{
6161     __ movl($dst$$Register, $mem$$Address);
6162   %}
6163   ins_pipe(ialu_reg_mem); // XXX
6164 %}
6165 
6166 // Load Float
6167 instruct loadF(regF dst, memory mem)
6168 %{
6169   match(Set dst (LoadF mem));
6170 
6171   ins_cost(145); // XXX
6172   format %{ "movss   $dst, $mem\t# float" %}
6173   opcode(0xF3, 0x0F, 0x10);
6174   ins_encode(OpcP, REX_reg_mem(dst, mem), OpcS, OpcT, reg_mem(dst, mem));
6175   ins_pipe(pipe_slow); // XXX
6176 %}
6177 
6178 // Load Double
6179 instruct loadD_partial(regD dst, memory mem)
6180 %{
6181   predicate(!UseXmmLoadAndClearUpper);
6182   match(Set dst (LoadD mem));
6183 
6184   ins_cost(145); // XXX
6185   format %{ "movlpd  $dst, $mem\t# double" %}
6186   opcode(0x66, 0x0F, 0x12);
6187   ins_encode(OpcP, REX_reg_mem(dst, mem), OpcS, OpcT, reg_mem(dst, mem));
6188   ins_pipe(pipe_slow); // XXX
6189 %}
6190 
6191 instruct loadD(regD dst, memory mem)
6192 %{
6193   predicate(UseXmmLoadAndClearUpper);
6194   match(Set dst (LoadD mem));
6195 
6196   ins_cost(145); // XXX
6197   format %{ "movsd   $dst, $mem\t# double" %}
6198   opcode(0xF2, 0x0F, 0x10);
6199   ins_encode(OpcP, REX_reg_mem(dst, mem), OpcS, OpcT, reg_mem(dst, mem));
6200   ins_pipe(pipe_slow); // XXX
6201 %}
6202 
6203 // Load Aligned Packed Byte to XMM register
6204 instruct loadA8B(regD dst, memory mem) %{
6205   match(Set dst (Load8B mem));
6206   ins_cost(125);
6207   format %{ "MOVQ  $dst,$mem\t! packed8B" %}
6208   ins_encode( movq_ld(dst, mem));
6209   ins_pipe( pipe_slow );
6210 %}
6211 
6212 // Load Aligned Packed Short to XMM register
6213 instruct loadA4S(regD dst, memory mem) %{
6214   match(Set dst (Load4S mem));
6215   ins_cost(125);
6216   format %{ "MOVQ  $dst,$mem\t! packed4S" %}
6217   ins_encode( movq_ld(dst, mem));
6218   ins_pipe( pipe_slow );
6219 %}
6220 
6221 // Load Aligned Packed Char to XMM register
6222 instruct loadA4C(regD dst, memory mem) %{
6223   match(Set dst (Load4C mem));
6224   ins_cost(125);
6225   format %{ "MOVQ  $dst,$mem\t! packed4C" %}
6226   ins_encode( movq_ld(dst, mem));
6227   ins_pipe( pipe_slow );
6228 %}
6229 
6230 // Load Aligned Packed Integer to XMM register
6231 instruct load2IU(regD dst, memory mem) %{
6232   match(Set dst (Load2I mem));
6233   ins_cost(125);
6234   format %{ "MOVQ  $dst,$mem\t! packed2I" %}
6235   ins_encode( movq_ld(dst, mem));
6236   ins_pipe( pipe_slow );
6237 %}
6238 
6239 // Load Aligned Packed Single to XMM
6240 instruct loadA2F(regD dst, memory mem) %{
6241   match(Set dst (Load2F mem));
6242   ins_cost(145);
6243   format %{ "MOVQ  $dst,$mem\t! packed2F" %}
6244   ins_encode( movq_ld(dst, mem));
6245   ins_pipe( pipe_slow );
6246 %}
6247 
6248 // Load Effective Address
6249 instruct leaP8(rRegP dst, indOffset8 mem)
6250 %{
6251   match(Set dst mem);
6252 
6253   ins_cost(110); // XXX
6254   format %{ "leaq    $dst, $mem\t# ptr 8" %}
6255   opcode(0x8D);
6256   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
6257   ins_pipe(ialu_reg_reg_fat);
6258 %}
6259 
6260 instruct leaP32(rRegP dst, indOffset32 mem)
6261 %{
6262   match(Set dst mem);
6263 
6264   ins_cost(110);
6265   format %{ "leaq    $dst, $mem\t# ptr 32" %}
6266   opcode(0x8D);
6267   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
6268   ins_pipe(ialu_reg_reg_fat);
6269 %}
6270 
6271 // instruct leaPIdx(rRegP dst, indIndex mem)
6272 // %{
6273 //   match(Set dst mem);
6274 
6275 //   ins_cost(110);
6276 //   format %{ "leaq    $dst, $mem\t# ptr idx" %}
6277 //   opcode(0x8D);
6278 //   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
6279 //   ins_pipe(ialu_reg_reg_fat);
6280 // %}
6281 
6282 instruct leaPIdxOff(rRegP dst, indIndexOffset mem)
6283 %{
6284   match(Set dst mem);
6285 
6286   ins_cost(110);
6287   format %{ "leaq    $dst, $mem\t# ptr idxoff" %}
6288   opcode(0x8D);
6289   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
6290   ins_pipe(ialu_reg_reg_fat);
6291 %}
6292 
6293 instruct leaPIdxScale(rRegP dst, indIndexScale mem)
6294 %{
6295   match(Set dst mem);
6296 
6297   ins_cost(110);
6298   format %{ "leaq    $dst, $mem\t# ptr idxscale" %}
6299   opcode(0x8D);
6300   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
6301   ins_pipe(ialu_reg_reg_fat);
6302 %}
6303 
6304 instruct leaPIdxScaleOff(rRegP dst, indIndexScaleOffset mem)
6305 %{
6306   match(Set dst mem);
6307 
6308   ins_cost(110);
6309   format %{ "leaq    $dst, $mem\t# ptr idxscaleoff" %}
6310   opcode(0x8D);
6311   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
6312   ins_pipe(ialu_reg_reg_fat);
6313 %}
6314 
6315 instruct leaPPosIdxScaleOff(rRegP dst, indPosIndexScaleOffset mem)
6316 %{
6317   match(Set dst mem);
6318 
6319   ins_cost(110);
6320   format %{ "leaq    $dst, $mem\t# ptr posidxscaleoff" %}
6321   opcode(0x8D);
6322   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
6323   ins_pipe(ialu_reg_reg_fat);
6324 %}
6325 
6326 // Load Effective Address which uses Narrow (32-bits) oop
6327 instruct leaPCompressedOopOffset(rRegP dst, indCompressedOopOffset mem)
6328 %{
6329   predicate(UseCompressedOops && (Universe::narrow_oop_shift() != 0));
6330   match(Set dst mem);
6331 
6332   ins_cost(110);
6333   format %{ "leaq    $dst, $mem\t# ptr compressedoopoff32" %}
6334   opcode(0x8D);
6335   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
6336   ins_pipe(ialu_reg_reg_fat);
6337 %}
6338 
6339 instruct leaP8Narrow(rRegP dst, indOffset8Narrow mem)
6340 %{
6341   predicate(Universe::narrow_oop_shift() == 0);
6342   match(Set dst mem);
6343 
6344   ins_cost(110); // XXX
6345   format %{ "leaq    $dst, $mem\t# ptr off8narrow" %}
6346   opcode(0x8D);
6347   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
6348   ins_pipe(ialu_reg_reg_fat);
6349 %}
6350 
6351 instruct leaP32Narrow(rRegP dst, indOffset32Narrow mem)
6352 %{
6353   predicate(Universe::narrow_oop_shift() == 0);
6354   match(Set dst mem);
6355 
6356   ins_cost(110);
6357   format %{ "leaq    $dst, $mem\t# ptr off32narrow" %}
6358   opcode(0x8D);
6359   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
6360   ins_pipe(ialu_reg_reg_fat);
6361 %}
6362 
6363 instruct leaPIdxOffNarrow(rRegP dst, indIndexOffsetNarrow mem)
6364 %{
6365   predicate(Universe::narrow_oop_shift() == 0);
6366   match(Set dst mem);
6367 
6368   ins_cost(110);
6369   format %{ "leaq    $dst, $mem\t# ptr idxoffnarrow" %}
6370   opcode(0x8D);
6371   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
6372   ins_pipe(ialu_reg_reg_fat);
6373 %}
6374 
6375 instruct leaPIdxScaleNarrow(rRegP dst, indIndexScaleNarrow mem)
6376 %{
6377   predicate(Universe::narrow_oop_shift() == 0);
6378   match(Set dst mem);
6379 
6380   ins_cost(110);
6381   format %{ "leaq    $dst, $mem\t# ptr idxscalenarrow" %}
6382   opcode(0x8D);
6383   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
6384   ins_pipe(ialu_reg_reg_fat);
6385 %}
6386 
6387 instruct leaPIdxScaleOffNarrow(rRegP dst, indIndexScaleOffsetNarrow mem)
6388 %{
6389   predicate(Universe::narrow_oop_shift() == 0);
6390   match(Set dst mem);
6391 
6392   ins_cost(110);
6393   format %{ "leaq    $dst, $mem\t# ptr idxscaleoffnarrow" %}
6394   opcode(0x8D);
6395   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
6396   ins_pipe(ialu_reg_reg_fat);
6397 %}
6398 
6399 instruct leaPPosIdxScaleOffNarrow(rRegP dst, indPosIndexScaleOffsetNarrow mem)
6400 %{
6401   predicate(Universe::narrow_oop_shift() == 0);
6402   match(Set dst mem);
6403 
6404   ins_cost(110);
6405   format %{ "leaq    $dst, $mem\t# ptr posidxscaleoffnarrow" %}
6406   opcode(0x8D);
6407   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
6408   ins_pipe(ialu_reg_reg_fat);
6409 %}
6410 
6411 instruct loadConI(rRegI dst, immI src)
6412 %{
6413   match(Set dst src);
6414 
6415   format %{ "movl    $dst, $src\t# int" %}
6416   ins_encode(load_immI(dst, src));
6417   ins_pipe(ialu_reg_fat); // XXX
6418 %}
6419 
6420 instruct loadConI0(rRegI dst, immI0 src, rFlagsReg cr)
6421 %{
6422   match(Set dst src);
6423   effect(KILL cr);
6424 
6425   ins_cost(50);
6426   format %{ "xorl    $dst, $dst\t# int" %}
6427   opcode(0x33); /* + rd */
6428   ins_encode(REX_reg_reg(dst, dst), OpcP, reg_reg(dst, dst));
6429   ins_pipe(ialu_reg);
6430 %}
6431 
6432 instruct loadConL(rRegL dst, immL src)
6433 %{
6434   match(Set dst src);
6435 
6436   ins_cost(150);
6437   format %{ "movq    $dst, $src\t# long" %}
6438   ins_encode(load_immL(dst, src));
6439   ins_pipe(ialu_reg);
6440 %}
6441 
6442 instruct loadConL0(rRegL dst, immL0 src, rFlagsReg cr)
6443 %{
6444   match(Set dst src);
6445   effect(KILL cr);
6446 
6447   ins_cost(50);
6448   format %{ "xorl    $dst, $dst\t# long" %}
6449   opcode(0x33); /* + rd */
6450   ins_encode(REX_reg_reg(dst, dst), OpcP, reg_reg(dst, dst));
6451   ins_pipe(ialu_reg); // XXX
6452 %}
6453 
6454 instruct loadConUL32(rRegL dst, immUL32 src)
6455 %{
6456   match(Set dst src);
6457 
6458   ins_cost(60);
6459   format %{ "movl    $dst, $src\t# long (unsigned 32-bit)" %}
6460   ins_encode(load_immUL32(dst, src));
6461   ins_pipe(ialu_reg);
6462 %}
6463 
6464 instruct loadConL32(rRegL dst, immL32 src)
6465 %{
6466   match(Set dst src);
6467 
6468   ins_cost(70);
6469   format %{ "movq    $dst, $src\t# long (32-bit)" %}
6470   ins_encode(load_immL32(dst, src));
6471   ins_pipe(ialu_reg);
6472 %}
6473 
6474 instruct loadConP(rRegP dst, immP con) %{
6475   match(Set dst con);
6476 
6477   format %{ "movq    $dst, $con\t# ptr" %}
6478   ins_encode(load_immP(dst, con));
6479   ins_pipe(ialu_reg_fat); // XXX
6480 %}
6481 
6482 instruct loadConP0(rRegP dst, immP0 src, rFlagsReg cr)
6483 %{
6484   match(Set dst src);
6485   effect(KILL cr);
6486 
6487   ins_cost(50);
6488   format %{ "xorl    $dst, $dst\t# ptr" %}
6489   opcode(0x33); /* + rd */
6490   ins_encode(REX_reg_reg(dst, dst), OpcP, reg_reg(dst, dst));
6491   ins_pipe(ialu_reg);
6492 %}
6493 
6494 instruct loadConP_poll(rRegP dst, immP_poll src) %{
6495   match(Set dst src);
6496   format %{ "movq    $dst, $src\t!ptr" %}
6497   ins_encode %{
6498     AddressLiteral polling_page(os::get_polling_page(), relocInfo::poll_type);
6499     __ lea($dst$$Register, polling_page);
6500   %}
6501   ins_pipe(ialu_reg_fat);
6502 %}
6503 
6504 instruct loadConP31(rRegP dst, immP31 src, rFlagsReg cr)
6505 %{
6506   match(Set dst src);
6507   effect(KILL cr);
6508 
6509   ins_cost(60);
6510   format %{ "movl    $dst, $src\t# ptr (positive 32-bit)" %}
6511   ins_encode(load_immP31(dst, src));
6512   ins_pipe(ialu_reg);
6513 %}
6514 
6515 instruct loadConF(regF dst, immF con) %{
6516   match(Set dst con);
6517   ins_cost(125);
6518   format %{ "movss   $dst, [$constantaddress]\t# load from constant table: float=$con" %}
6519   ins_encode %{
6520     __ movflt($dst$$XMMRegister, $constantaddress($con));
6521   %}
6522   ins_pipe(pipe_slow);
6523 %}
6524 
6525 instruct loadConN0(rRegN dst, immN0 src, rFlagsReg cr) %{
6526   match(Set dst src);
6527   effect(KILL cr);
6528   format %{ "xorq    $dst, $src\t# compressed NULL ptr" %}
6529   ins_encode %{
6530     __ xorq($dst$$Register, $dst$$Register);
6531   %}
6532   ins_pipe(ialu_reg);
6533 %}
6534 
6535 instruct loadConN(rRegN dst, immN src) %{
6536   match(Set dst src);
6537 
6538   ins_cost(125);
6539   format %{ "movl    $dst, $src\t# compressed ptr" %}
6540   ins_encode %{
6541     address con = (address)$src$$constant;
6542     if (con == NULL) {
6543       ShouldNotReachHere();
6544     } else {
6545       __ set_narrow_oop($dst$$Register, (jobject)$src$$constant);
6546     }
6547   %}
6548   ins_pipe(ialu_reg_fat); // XXX
6549 %}
6550 
6551 instruct loadConF0(regF dst, immF0 src)
6552 %{
6553   match(Set dst src);
6554   ins_cost(100);
6555 
6556   format %{ "xorps   $dst, $dst\t# float 0.0" %}
6557   opcode(0x0F, 0x57);
6558   ins_encode(REX_reg_reg(dst, dst), OpcP, OpcS, reg_reg(dst, dst));
6559   ins_pipe(pipe_slow);
6560 %}
6561 
6562 // Use the same format since predicate() can not be used here.
6563 instruct loadConD(regD dst, immD con) %{
6564   match(Set dst con);
6565   ins_cost(125);
6566   format %{ "movsd   $dst, [$constantaddress]\t# load from constant table: double=$con" %}
6567   ins_encode %{
6568     __ movdbl($dst$$XMMRegister, $constantaddress($con));
6569   %}
6570   ins_pipe(pipe_slow);
6571 %}
6572 
6573 instruct loadConD0(regD dst, immD0 src)
6574 %{
6575   match(Set dst src);
6576   ins_cost(100);
6577 
6578   format %{ "xorpd   $dst, $dst\t# double 0.0" %}
6579   opcode(0x66, 0x0F, 0x57);
6580   ins_encode(OpcP, REX_reg_reg(dst, dst), OpcS, OpcT, reg_reg(dst, dst));
6581   ins_pipe(pipe_slow);
6582 %}
6583 
6584 instruct loadSSI(rRegI dst, stackSlotI src)
6585 %{
6586   match(Set dst src);
6587 
6588   ins_cost(125);
6589   format %{ "movl    $dst, $src\t# int stk" %}
6590   opcode(0x8B);
6591   ins_encode(REX_reg_mem(dst, src), OpcP, reg_mem(dst, src));
6592   ins_pipe(ialu_reg_mem);
6593 %}
6594 
6595 instruct loadSSL(rRegL dst, stackSlotL src)
6596 %{
6597   match(Set dst src);
6598 
6599   ins_cost(125);
6600   format %{ "movq    $dst, $src\t# long stk" %}
6601   opcode(0x8B);
6602   ins_encode(REX_reg_mem_wide(dst, src), OpcP, reg_mem(dst, src));
6603   ins_pipe(ialu_reg_mem);
6604 %}
6605 
6606 instruct loadSSP(rRegP dst, stackSlotP src)
6607 %{
6608   match(Set dst src);
6609 
6610   ins_cost(125);
6611   format %{ "movq    $dst, $src\t# ptr stk" %}
6612   opcode(0x8B);
6613   ins_encode(REX_reg_mem_wide(dst, src), OpcP, reg_mem(dst, src));
6614   ins_pipe(ialu_reg_mem);
6615 %}
6616 
6617 instruct loadSSF(regF dst, stackSlotF src)
6618 %{
6619   match(Set dst src);
6620 
6621   ins_cost(125);
6622   format %{ "movss   $dst, $src\t# float stk" %}
6623   opcode(0xF3, 0x0F, 0x10);
6624   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
6625   ins_pipe(pipe_slow); // XXX
6626 %}
6627 
6628 // Use the same format since predicate() can not be used here.
6629 instruct loadSSD(regD dst, stackSlotD src)
6630 %{
6631   match(Set dst src);
6632 
6633   ins_cost(125);
6634   format %{ "movsd   $dst, $src\t# double stk" %}
6635   ins_encode  %{
6636     __ movdbl($dst$$XMMRegister, Address(rsp, $src$$disp));
6637   %}
6638   ins_pipe(pipe_slow); // XXX
6639 %}
6640 
6641 // Prefetch instructions.
6642 // Must be safe to execute with invalid address (cannot fault).
6643 
6644 instruct prefetchr( memory mem ) %{
6645   predicate(ReadPrefetchInstr==3);
6646   match(PrefetchRead mem);
6647   ins_cost(125);
6648 
6649   format %{ "PREFETCHR $mem\t# Prefetch into level 1 cache" %}
6650   opcode(0x0F, 0x0D);     /* Opcode 0F 0D /0 */
6651   ins_encode(REX_mem(mem), OpcP, OpcS, RM_opc_mem(0x00, mem));
6652   ins_pipe(ialu_mem);
6653 %}
6654 
6655 instruct prefetchrNTA( memory mem ) %{
6656   predicate(ReadPrefetchInstr==0);
6657   match(PrefetchRead mem);
6658   ins_cost(125);
6659 
6660   format %{ "PREFETCHNTA $mem\t# Prefetch into non-temporal cache for read" %}
6661   opcode(0x0F, 0x18);     /* Opcode 0F 18 /0 */
6662   ins_encode(REX_mem(mem), OpcP, OpcS, RM_opc_mem(0x00, mem));
6663   ins_pipe(ialu_mem);
6664 %}
6665 
6666 instruct prefetchrT0( memory mem ) %{
6667   predicate(ReadPrefetchInstr==1);
6668   match(PrefetchRead mem);
6669   ins_cost(125);
6670 
6671   format %{ "PREFETCHT0 $mem\t# prefetch into L1 and L2 caches for read" %}
6672   opcode(0x0F, 0x18); /* Opcode 0F 18 /1 */
6673   ins_encode(REX_mem(mem), OpcP, OpcS, RM_opc_mem(0x01, mem));
6674   ins_pipe(ialu_mem);
6675 %}
6676 
6677 instruct prefetchrT2( memory mem ) %{
6678   predicate(ReadPrefetchInstr==2);
6679   match(PrefetchRead mem);
6680   ins_cost(125);
6681 
6682   format %{ "PREFETCHT2 $mem\t# prefetch into L2 caches for read" %}
6683   opcode(0x0F, 0x18); /* Opcode 0F 18 /3 */
6684   ins_encode(REX_mem(mem), OpcP, OpcS, RM_opc_mem(0x03, mem));
6685   ins_pipe(ialu_mem);
6686 %}
6687 
6688 instruct prefetchw( memory mem ) %{
6689   predicate(AllocatePrefetchInstr==3);
6690   match(PrefetchWrite mem);
6691   ins_cost(125);
6692 
6693   format %{ "PREFETCHW $mem\t# Prefetch into level 1 cache and mark modified" %}
6694   opcode(0x0F, 0x0D);     /* Opcode 0F 0D /1 */
6695   ins_encode(REX_mem(mem), OpcP, OpcS, RM_opc_mem(0x01, mem));
6696   ins_pipe(ialu_mem);
6697 %}
6698 
6699 instruct prefetchwNTA( memory mem ) %{
6700   predicate(AllocatePrefetchInstr==0);
6701   match(PrefetchWrite mem);
6702   ins_cost(125);
6703 
6704   format %{ "PREFETCHNTA $mem\t# Prefetch to non-temporal cache for write" %}
6705   opcode(0x0F, 0x18);     /* Opcode 0F 18 /0 */
6706   ins_encode(REX_mem(mem), OpcP, OpcS, RM_opc_mem(0x00, mem));
6707   ins_pipe(ialu_mem);
6708 %}
6709 
6710 instruct prefetchwT0( memory mem ) %{
6711   predicate(AllocatePrefetchInstr==1);
6712   match(PrefetchWrite mem);
6713   ins_cost(125);
6714 
6715   format %{ "PREFETCHT0 $mem\t# Prefetch to level 1 and 2 caches for write" %}
6716   opcode(0x0F, 0x18);     /* Opcode 0F 18 /1 */
6717   ins_encode(REX_mem(mem), OpcP, OpcS, RM_opc_mem(0x01, mem));
6718   ins_pipe(ialu_mem);
6719 %}
6720 
6721 instruct prefetchwT2( memory mem ) %{
6722   predicate(AllocatePrefetchInstr==2);
6723   match(PrefetchWrite mem);
6724   ins_cost(125);
6725 
6726   format %{ "PREFETCHT2 $mem\t# Prefetch to level 2 cache for write" %}
6727   opcode(0x0F, 0x18);     /* Opcode 0F 18 /3 */
6728   ins_encode(REX_mem(mem), OpcP, OpcS, RM_opc_mem(0x03, mem));
6729   ins_pipe(ialu_mem);
6730 %}
6731 
6732 //----------Store Instructions-------------------------------------------------
6733 
6734 // Store Byte
6735 instruct storeB(memory mem, rRegI src)
6736 %{
6737   match(Set mem (StoreB mem src));
6738 
6739   ins_cost(125); // XXX
6740   format %{ "movb    $mem, $src\t# byte" %}
6741   opcode(0x88);
6742   ins_encode(REX_breg_mem(src, mem), OpcP, reg_mem(src, mem));
6743   ins_pipe(ialu_mem_reg);
6744 %}
6745 
6746 // Store Char/Short
6747 instruct storeC(memory mem, rRegI src)
6748 %{
6749   match(Set mem (StoreC mem src));
6750 
6751   ins_cost(125); // XXX
6752   format %{ "movw    $mem, $src\t# char/short" %}
6753   opcode(0x89);
6754   ins_encode(SizePrefix, REX_reg_mem(src, mem), OpcP, reg_mem(src, mem));
6755   ins_pipe(ialu_mem_reg);
6756 %}
6757 
6758 // Store Integer
6759 instruct storeI(memory mem, rRegI src)
6760 %{
6761   match(Set mem (StoreI mem src));
6762 
6763   ins_cost(125); // XXX
6764   format %{ "movl    $mem, $src\t# int" %}
6765   opcode(0x89);
6766   ins_encode(REX_reg_mem(src, mem), OpcP, reg_mem(src, mem));
6767   ins_pipe(ialu_mem_reg);
6768 %}
6769 
6770 // Store Long
6771 instruct storeL(memory mem, rRegL src)
6772 %{
6773   match(Set mem (StoreL mem src));
6774 
6775   ins_cost(125); // XXX
6776   format %{ "movq    $mem, $src\t# long" %}
6777   opcode(0x89);
6778   ins_encode(REX_reg_mem_wide(src, mem), OpcP, reg_mem(src, mem));
6779   ins_pipe(ialu_mem_reg); // XXX
6780 %}
6781 
6782 // Store Pointer
6783 instruct storeP(memory mem, any_RegP src)
6784 %{
6785   match(Set mem (StoreP mem src));
6786 
6787   ins_cost(125); // XXX
6788   format %{ "movq    $mem, $src\t# ptr" %}
6789   opcode(0x89);
6790   ins_encode(REX_reg_mem_wide(src, mem), OpcP, reg_mem(src, mem));
6791   ins_pipe(ialu_mem_reg);
6792 %}
6793 
6794 instruct storeImmP0(memory mem, immP0 zero)
6795 %{
6796   predicate(UseCompressedOops && (Universe::narrow_oop_base() == NULL));
6797   match(Set mem (StoreP mem zero));
6798 
6799   ins_cost(125); // XXX
6800   format %{ "movq    $mem, R12\t# ptr (R12_heapbase==0)" %}
6801   ins_encode %{
6802     __ movq($mem$$Address, r12);
6803   %}
6804   ins_pipe(ialu_mem_reg);
6805 %}
6806 
6807 // Store NULL Pointer, mark word, or other simple pointer constant.
6808 instruct storeImmP(memory mem, immP31 src)
6809 %{
6810   match(Set mem (StoreP mem src));
6811 
6812   ins_cost(150); // XXX
6813   format %{ "movq    $mem, $src\t# ptr" %}
6814   opcode(0xC7); /* C7 /0 */
6815   ins_encode(REX_mem_wide(mem), OpcP, RM_opc_mem(0x00, mem), Con32(src));
6816   ins_pipe(ialu_mem_imm);
6817 %}
6818 
6819 // Store Compressed Pointer
6820 instruct storeN(memory mem, rRegN src)
6821 %{
6822   match(Set mem (StoreN mem src));
6823 
6824   ins_cost(125); // XXX
6825   format %{ "movl    $mem, $src\t# compressed ptr" %}
6826   ins_encode %{
6827     __ movl($mem$$Address, $src$$Register);
6828   %}
6829   ins_pipe(ialu_mem_reg);
6830 %}
6831 
6832 instruct storeImmN0(memory mem, immN0 zero)
6833 %{
6834   predicate(Universe::narrow_oop_base() == NULL);
6835   match(Set mem (StoreN mem zero));
6836 
6837   ins_cost(125); // XXX
6838   format %{ "movl    $mem, R12\t# compressed ptr (R12_heapbase==0)" %}
6839   ins_encode %{
6840     __ movl($mem$$Address, r12);
6841   %}
6842   ins_pipe(ialu_mem_reg);
6843 %}
6844 
6845 instruct storeImmN(memory mem, immN src)
6846 %{
6847   match(Set mem (StoreN mem src));
6848 
6849   ins_cost(150); // XXX
6850   format %{ "movl    $mem, $src\t# compressed ptr" %}
6851   ins_encode %{
6852     address con = (address)$src$$constant;
6853     if (con == NULL) {
6854       __ movl($mem$$Address, (int32_t)0);
6855     } else {
6856       __ set_narrow_oop($mem$$Address, (jobject)$src$$constant);
6857     }
6858   %}
6859   ins_pipe(ialu_mem_imm);
6860 %}
6861 
6862 // Store Integer Immediate
6863 instruct storeImmI0(memory mem, immI0 zero)
6864 %{
6865   predicate(UseCompressedOops && (Universe::narrow_oop_base() == NULL));
6866   match(Set mem (StoreI mem zero));
6867 
6868   ins_cost(125); // XXX
6869   format %{ "movl    $mem, R12\t# int (R12_heapbase==0)" %}
6870   ins_encode %{
6871     __ movl($mem$$Address, r12);
6872   %}
6873   ins_pipe(ialu_mem_reg);
6874 %}
6875 
6876 instruct storeImmI(memory mem, immI src)
6877 %{
6878   match(Set mem (StoreI mem src));
6879 
6880   ins_cost(150);
6881   format %{ "movl    $mem, $src\t# int" %}
6882   opcode(0xC7); /* C7 /0 */
6883   ins_encode(REX_mem(mem), OpcP, RM_opc_mem(0x00, mem), Con32(src));
6884   ins_pipe(ialu_mem_imm);
6885 %}
6886 
6887 // Store Long Immediate
6888 instruct storeImmL0(memory mem, immL0 zero)
6889 %{
6890   predicate(UseCompressedOops && (Universe::narrow_oop_base() == NULL));
6891   match(Set mem (StoreL mem zero));
6892 
6893   ins_cost(125); // XXX
6894   format %{ "movq    $mem, R12\t# long (R12_heapbase==0)" %}
6895   ins_encode %{
6896     __ movq($mem$$Address, r12);
6897   %}
6898   ins_pipe(ialu_mem_reg);
6899 %}
6900 
6901 instruct storeImmL(memory mem, immL32 src)
6902 %{
6903   match(Set mem (StoreL mem src));
6904 
6905   ins_cost(150);
6906   format %{ "movq    $mem, $src\t# long" %}
6907   opcode(0xC7); /* C7 /0 */
6908   ins_encode(REX_mem_wide(mem), OpcP, RM_opc_mem(0x00, mem), Con32(src));
6909   ins_pipe(ialu_mem_imm);
6910 %}
6911 
6912 // Store Short/Char Immediate
6913 instruct storeImmC0(memory mem, immI0 zero)
6914 %{
6915   predicate(UseCompressedOops && (Universe::narrow_oop_base() == NULL));
6916   match(Set mem (StoreC mem zero));
6917 
6918   ins_cost(125); // XXX
6919   format %{ "movw    $mem, R12\t# short/char (R12_heapbase==0)" %}
6920   ins_encode %{
6921     __ movw($mem$$Address, r12);
6922   %}
6923   ins_pipe(ialu_mem_reg);
6924 %}
6925 
6926 instruct storeImmI16(memory mem, immI16 src)
6927 %{
6928   predicate(UseStoreImmI16);
6929   match(Set mem (StoreC mem src));
6930 
6931   ins_cost(150);
6932   format %{ "movw    $mem, $src\t# short/char" %}
6933   opcode(0xC7); /* C7 /0 Same as 32 store immediate with prefix */
6934   ins_encode(SizePrefix, REX_mem(mem), OpcP, RM_opc_mem(0x00, mem),Con16(src));
6935   ins_pipe(ialu_mem_imm);
6936 %}
6937 
6938 // Store Byte Immediate
6939 instruct storeImmB0(memory mem, immI0 zero)
6940 %{
6941   predicate(UseCompressedOops && (Universe::narrow_oop_base() == NULL));
6942   match(Set mem (StoreB mem zero));
6943 
6944   ins_cost(125); // XXX
6945   format %{ "movb    $mem, R12\t# short/char (R12_heapbase==0)" %}
6946   ins_encode %{
6947     __ movb($mem$$Address, r12);
6948   %}
6949   ins_pipe(ialu_mem_reg);
6950 %}
6951 
6952 instruct storeImmB(memory mem, immI8 src)
6953 %{
6954   match(Set mem (StoreB mem src));
6955 
6956   ins_cost(150); // XXX
6957   format %{ "movb    $mem, $src\t# byte" %}
6958   opcode(0xC6); /* C6 /0 */
6959   ins_encode(REX_mem(mem), OpcP, RM_opc_mem(0x00, mem), Con8or32(src));
6960   ins_pipe(ialu_mem_imm);
6961 %}
6962 
6963 // Store Aligned Packed Byte XMM register to memory
6964 instruct storeA8B(memory mem, regD src) %{
6965   match(Set mem (Store8B mem src));
6966   ins_cost(145);
6967   format %{ "MOVQ  $mem,$src\t! packed8B" %}
6968   ins_encode( movq_st(mem, src));
6969   ins_pipe( pipe_slow );
6970 %}
6971 
6972 // Store Aligned Packed Char/Short XMM register to memory
6973 instruct storeA4C(memory mem, regD src) %{
6974   match(Set mem (Store4C mem src));
6975   ins_cost(145);
6976   format %{ "MOVQ  $mem,$src\t! packed4C" %}
6977   ins_encode( movq_st(mem, src));
6978   ins_pipe( pipe_slow );
6979 %}
6980 
6981 // Store Aligned Packed Integer XMM register to memory
6982 instruct storeA2I(memory mem, regD src) %{
6983   match(Set mem (Store2I mem src));
6984   ins_cost(145);
6985   format %{ "MOVQ  $mem,$src\t! packed2I" %}
6986   ins_encode( movq_st(mem, src));
6987   ins_pipe( pipe_slow );
6988 %}
6989 
6990 // Store CMS card-mark Immediate
6991 instruct storeImmCM0_reg(memory mem, immI0 zero)
6992 %{
6993   predicate(UseCompressedOops && (Universe::narrow_oop_base() == NULL));
6994   match(Set mem (StoreCM mem zero));
6995 
6996   ins_cost(125); // XXX
6997   format %{ "movb    $mem, R12\t# CMS card-mark byte 0 (R12_heapbase==0)" %}
6998   ins_encode %{
6999     __ movb($mem$$Address, r12);
7000   %}
7001   ins_pipe(ialu_mem_reg);
7002 %}
7003 
7004 instruct storeImmCM0(memory mem, immI0 src)
7005 %{
7006   match(Set mem (StoreCM mem src));
7007 
7008   ins_cost(150); // XXX
7009   format %{ "movb    $mem, $src\t# CMS card-mark byte 0" %}
7010   opcode(0xC6); /* C6 /0 */
7011   ins_encode(REX_mem(mem), OpcP, RM_opc_mem(0x00, mem), Con8or32(src));
7012   ins_pipe(ialu_mem_imm);
7013 %}
7014 
7015 // Store Aligned Packed Single Float XMM register to memory
7016 instruct storeA2F(memory mem, regD src) %{
7017   match(Set mem (Store2F mem src));
7018   ins_cost(145);
7019   format %{ "MOVQ  $mem,$src\t! packed2F" %}
7020   ins_encode( movq_st(mem, src));
7021   ins_pipe( pipe_slow );
7022 %}
7023 
7024 // Store Float
7025 instruct storeF(memory mem, regF src)
7026 %{
7027   match(Set mem (StoreF mem src));
7028 
7029   ins_cost(95); // XXX
7030   format %{ "movss   $mem, $src\t# float" %}
7031   opcode(0xF3, 0x0F, 0x11);
7032   ins_encode(OpcP, REX_reg_mem(src, mem), OpcS, OpcT, reg_mem(src, mem));
7033   ins_pipe(pipe_slow); // XXX
7034 %}
7035 
7036 // Store immediate Float value (it is faster than store from XMM register)
7037 instruct storeF0(memory mem, immF0 zero)
7038 %{
7039   predicate(UseCompressedOops && (Universe::narrow_oop_base() == NULL));
7040   match(Set mem (StoreF mem zero));
7041 
7042   ins_cost(25); // XXX
7043   format %{ "movl    $mem, R12\t# float 0. (R12_heapbase==0)" %}
7044   ins_encode %{
7045     __ movl($mem$$Address, r12);
7046   %}
7047   ins_pipe(ialu_mem_reg);
7048 %}
7049 
7050 instruct storeF_imm(memory mem, immF src)
7051 %{
7052   match(Set mem (StoreF mem src));
7053 
7054   ins_cost(50);
7055   format %{ "movl    $mem, $src\t# float" %}
7056   opcode(0xC7); /* C7 /0 */
7057   ins_encode(REX_mem(mem), OpcP, RM_opc_mem(0x00, mem), Con32F_as_bits(src));
7058   ins_pipe(ialu_mem_imm);
7059 %}
7060 
7061 // Store Double
7062 instruct storeD(memory mem, regD src)
7063 %{
7064   match(Set mem (StoreD mem src));
7065 
7066   ins_cost(95); // XXX
7067   format %{ "movsd   $mem, $src\t# double" %}
7068   opcode(0xF2, 0x0F, 0x11);
7069   ins_encode(OpcP, REX_reg_mem(src, mem), OpcS, OpcT, reg_mem(src, mem));
7070   ins_pipe(pipe_slow); // XXX
7071 %}
7072 
7073 // Store immediate double 0.0 (it is faster than store from XMM register)
7074 instruct storeD0_imm(memory mem, immD0 src)
7075 %{
7076   predicate(!UseCompressedOops || (Universe::narrow_oop_base() != NULL));
7077   match(Set mem (StoreD mem src));
7078 
7079   ins_cost(50);
7080   format %{ "movq    $mem, $src\t# double 0." %}
7081   opcode(0xC7); /* C7 /0 */
7082   ins_encode(REX_mem_wide(mem), OpcP, RM_opc_mem(0x00, mem), Con32F_as_bits(src));
7083   ins_pipe(ialu_mem_imm);
7084 %}
7085 
7086 instruct storeD0(memory mem, immD0 zero)
7087 %{
7088   predicate(UseCompressedOops && (Universe::narrow_oop_base() == NULL));
7089   match(Set mem (StoreD mem zero));
7090 
7091   ins_cost(25); // XXX
7092   format %{ "movq    $mem, R12\t# double 0. (R12_heapbase==0)" %}
7093   ins_encode %{
7094     __ movq($mem$$Address, r12);
7095   %}
7096   ins_pipe(ialu_mem_reg);
7097 %}
7098 
7099 instruct storeSSI(stackSlotI dst, rRegI src)
7100 %{
7101   match(Set dst src);
7102 
7103   ins_cost(100);
7104   format %{ "movl    $dst, $src\t# int stk" %}
7105   opcode(0x89);
7106   ins_encode(REX_reg_mem(src, dst), OpcP, reg_mem(src, dst));
7107   ins_pipe( ialu_mem_reg );
7108 %}
7109 
7110 instruct storeSSL(stackSlotL dst, rRegL src)
7111 %{
7112   match(Set dst src);
7113 
7114   ins_cost(100);
7115   format %{ "movq    $dst, $src\t# long stk" %}
7116   opcode(0x89);
7117   ins_encode(REX_reg_mem_wide(src, dst), OpcP, reg_mem(src, dst));
7118   ins_pipe(ialu_mem_reg);
7119 %}
7120 
7121 instruct storeSSP(stackSlotP dst, rRegP src)
7122 %{
7123   match(Set dst src);
7124 
7125   ins_cost(100);
7126   format %{ "movq    $dst, $src\t# ptr stk" %}
7127   opcode(0x89);
7128   ins_encode(REX_reg_mem_wide(src, dst), OpcP, reg_mem(src, dst));
7129   ins_pipe(ialu_mem_reg);
7130 %}
7131 
7132 instruct storeSSF(stackSlotF dst, regF src)
7133 %{
7134   match(Set dst src);
7135 
7136   ins_cost(95); // XXX
7137   format %{ "movss   $dst, $src\t# float stk" %}
7138   opcode(0xF3, 0x0F, 0x11);
7139   ins_encode(OpcP, REX_reg_mem(src, dst), OpcS, OpcT, reg_mem(src, dst));
7140   ins_pipe(pipe_slow); // XXX
7141 %}
7142 
7143 instruct storeSSD(stackSlotD dst, regD src)
7144 %{
7145   match(Set dst src);
7146 
7147   ins_cost(95); // XXX
7148   format %{ "movsd   $dst, $src\t# double stk" %}
7149   opcode(0xF2, 0x0F, 0x11);
7150   ins_encode(OpcP, REX_reg_mem(src, dst), OpcS, OpcT, reg_mem(src, dst));
7151   ins_pipe(pipe_slow); // XXX
7152 %}
7153 
7154 //----------BSWAP Instructions-------------------------------------------------
7155 instruct bytes_reverse_int(rRegI dst) %{
7156   match(Set dst (ReverseBytesI dst));
7157 
7158   format %{ "bswapl  $dst" %}
7159   opcode(0x0F, 0xC8);  /*Opcode 0F /C8 */
7160   ins_encode( REX_reg(dst), OpcP, opc2_reg(dst) );
7161   ins_pipe( ialu_reg );
7162 %}
7163 
7164 instruct bytes_reverse_long(rRegL dst) %{
7165   match(Set dst (ReverseBytesL dst));
7166 
7167   format %{ "bswapq  $dst" %}
7168 
7169   opcode(0x0F, 0xC8); /* Opcode 0F /C8 */
7170   ins_encode( REX_reg_wide(dst), OpcP, opc2_reg(dst) );
7171   ins_pipe( ialu_reg);
7172 %}
7173 
7174 instruct bytes_reverse_unsigned_short(rRegI dst) %{
7175   match(Set dst (ReverseBytesUS dst));
7176 
7177   format %{ "bswapl  $dst\n\t"
7178             "shrl    $dst,16\n\t" %}
7179   ins_encode %{
7180     __ bswapl($dst$$Register);
7181     __ shrl($dst$$Register, 16);
7182   %}
7183   ins_pipe( ialu_reg );
7184 %}
7185 
7186 instruct bytes_reverse_short(rRegI dst) %{
7187   match(Set dst (ReverseBytesS dst));
7188 
7189   format %{ "bswapl  $dst\n\t"
7190             "sar     $dst,16\n\t" %}
7191   ins_encode %{
7192     __ bswapl($dst$$Register);
7193     __ sarl($dst$$Register, 16);
7194   %}
7195   ins_pipe( ialu_reg );
7196 %}
7197 
7198 //---------- Zeros Count Instructions ------------------------------------------
7199 
7200 instruct countLeadingZerosI(rRegI dst, rRegI src, rFlagsReg cr) %{
7201   predicate(UseCountLeadingZerosInstruction);
7202   match(Set dst (CountLeadingZerosI src));
7203   effect(KILL cr);
7204 
7205   format %{ "lzcntl  $dst, $src\t# count leading zeros (int)" %}
7206   ins_encode %{
7207     __ lzcntl($dst$$Register, $src$$Register);
7208   %}
7209   ins_pipe(ialu_reg);
7210 %}
7211 
7212 instruct countLeadingZerosI_bsr(rRegI dst, rRegI src, rFlagsReg cr) %{
7213   predicate(!UseCountLeadingZerosInstruction);
7214   match(Set dst (CountLeadingZerosI src));
7215   effect(KILL cr);
7216 
7217   format %{ "bsrl    $dst, $src\t# count leading zeros (int)\n\t"
7218             "jnz     skip\n\t"
7219             "movl    $dst, -1\n"
7220       "skip:\n\t"
7221             "negl    $dst\n\t"
7222             "addl    $dst, 31" %}
7223   ins_encode %{
7224     Register Rdst = $dst$$Register;
7225     Register Rsrc = $src$$Register;
7226     Label skip;
7227     __ bsrl(Rdst, Rsrc);
7228     __ jccb(Assembler::notZero, skip);
7229     __ movl(Rdst, -1);
7230     __ bind(skip);
7231     __ negl(Rdst);
7232     __ addl(Rdst, BitsPerInt - 1);
7233   %}
7234   ins_pipe(ialu_reg);
7235 %}
7236 
7237 instruct countLeadingZerosL(rRegI dst, rRegL src, rFlagsReg cr) %{
7238   predicate(UseCountLeadingZerosInstruction);
7239   match(Set dst (CountLeadingZerosL src));
7240   effect(KILL cr);
7241 
7242   format %{ "lzcntq  $dst, $src\t# count leading zeros (long)" %}
7243   ins_encode %{
7244     __ lzcntq($dst$$Register, $src$$Register);
7245   %}
7246   ins_pipe(ialu_reg);
7247 %}
7248 
7249 instruct countLeadingZerosL_bsr(rRegI dst, rRegL src, rFlagsReg cr) %{
7250   predicate(!UseCountLeadingZerosInstruction);
7251   match(Set dst (CountLeadingZerosL src));
7252   effect(KILL cr);
7253 
7254   format %{ "bsrq    $dst, $src\t# count leading zeros (long)\n\t"
7255             "jnz     skip\n\t"
7256             "movl    $dst, -1\n"
7257       "skip:\n\t"
7258             "negl    $dst\n\t"
7259             "addl    $dst, 63" %}
7260   ins_encode %{
7261     Register Rdst = $dst$$Register;
7262     Register Rsrc = $src$$Register;
7263     Label skip;
7264     __ bsrq(Rdst, Rsrc);
7265     __ jccb(Assembler::notZero, skip);
7266     __ movl(Rdst, -1);
7267     __ bind(skip);
7268     __ negl(Rdst);
7269     __ addl(Rdst, BitsPerLong - 1);
7270   %}
7271   ins_pipe(ialu_reg);
7272 %}
7273 
7274 instruct countTrailingZerosI(rRegI dst, rRegI src, rFlagsReg cr) %{
7275   match(Set dst (CountTrailingZerosI src));
7276   effect(KILL cr);
7277 
7278   format %{ "bsfl    $dst, $src\t# count trailing zeros (int)\n\t"
7279             "jnz     done\n\t"
7280             "movl    $dst, 32\n"
7281       "done:" %}
7282   ins_encode %{
7283     Register Rdst = $dst$$Register;
7284     Label done;
7285     __ bsfl(Rdst, $src$$Register);
7286     __ jccb(Assembler::notZero, done);
7287     __ movl(Rdst, BitsPerInt);
7288     __ bind(done);
7289   %}
7290   ins_pipe(ialu_reg);
7291 %}
7292 
7293 instruct countTrailingZerosL(rRegI dst, rRegL src, rFlagsReg cr) %{
7294   match(Set dst (CountTrailingZerosL src));
7295   effect(KILL cr);
7296 
7297   format %{ "bsfq    $dst, $src\t# count trailing zeros (long)\n\t"
7298             "jnz     done\n\t"
7299             "movl    $dst, 64\n"
7300       "done:" %}
7301   ins_encode %{
7302     Register Rdst = $dst$$Register;
7303     Label done;
7304     __ bsfq(Rdst, $src$$Register);
7305     __ jccb(Assembler::notZero, done);
7306     __ movl(Rdst, BitsPerLong);
7307     __ bind(done);
7308   %}
7309   ins_pipe(ialu_reg);
7310 %}
7311 
7312 
7313 //---------- Population Count Instructions -------------------------------------
7314 
7315 instruct popCountI(rRegI dst, rRegI src) %{
7316   predicate(UsePopCountInstruction);
7317   match(Set dst (PopCountI src));
7318 
7319   format %{ "popcnt  $dst, $src" %}
7320   ins_encode %{
7321     __ popcntl($dst$$Register, $src$$Register);
7322   %}
7323   ins_pipe(ialu_reg);
7324 %}
7325 
7326 instruct popCountI_mem(rRegI dst, memory mem) %{
7327   predicate(UsePopCountInstruction);
7328   match(Set dst (PopCountI (LoadI mem)));
7329 
7330   format %{ "popcnt  $dst, $mem" %}
7331   ins_encode %{
7332     __ popcntl($dst$$Register, $mem$$Address);
7333   %}
7334   ins_pipe(ialu_reg);
7335 %}
7336 
7337 // Note: Long.bitCount(long) returns an int.
7338 instruct popCountL(rRegI dst, rRegL src) %{
7339   predicate(UsePopCountInstruction);
7340   match(Set dst (PopCountL src));
7341 
7342   format %{ "popcnt  $dst, $src" %}
7343   ins_encode %{
7344     __ popcntq($dst$$Register, $src$$Register);
7345   %}
7346   ins_pipe(ialu_reg);
7347 %}
7348 
7349 // Note: Long.bitCount(long) returns an int.
7350 instruct popCountL_mem(rRegI dst, memory mem) %{
7351   predicate(UsePopCountInstruction);
7352   match(Set dst (PopCountL (LoadL mem)));
7353 
7354   format %{ "popcnt  $dst, $mem" %}
7355   ins_encode %{
7356     __ popcntq($dst$$Register, $mem$$Address);
7357   %}
7358   ins_pipe(ialu_reg);
7359 %}
7360 
7361 
7362 //----------MemBar Instructions-----------------------------------------------
7363 // Memory barrier flavors
7364 
7365 instruct membar_acquire()
7366 %{
7367   match(MemBarAcquire);
7368   ins_cost(0);
7369 
7370   size(0);
7371   format %{ "MEMBAR-acquire ! (empty encoding)" %}
7372   ins_encode();
7373   ins_pipe(empty);
7374 %}
7375 
7376 instruct membar_acquire_lock()
7377 %{
7378   match(MemBarAcquireLock);
7379   ins_cost(0);
7380 
7381   size(0);
7382   format %{ "MEMBAR-acquire (prior CMPXCHG in FastLock so empty encoding)" %}
7383   ins_encode();
7384   ins_pipe(empty);
7385 %}
7386 
7387 instruct membar_release()
7388 %{
7389   match(MemBarRelease);
7390   ins_cost(0);
7391 
7392   size(0);
7393   format %{ "MEMBAR-release ! (empty encoding)" %}
7394   ins_encode();
7395   ins_pipe(empty);
7396 %}
7397 
7398 instruct membar_release_lock()
7399 %{
7400   match(MemBarReleaseLock);
7401   ins_cost(0);
7402 
7403   size(0);
7404   format %{ "MEMBAR-release (a FastUnlock follows so empty encoding)" %}
7405   ins_encode();
7406   ins_pipe(empty);
7407 %}
7408 
7409 instruct membar_volatile(rFlagsReg cr) %{
7410   match(MemBarVolatile);
7411   effect(KILL cr);
7412   ins_cost(400);
7413 
7414   format %{
7415     $$template
7416     if (os::is_MP()) {
7417       $$emit$$"lock addl [rsp + #0], 0\t! membar_volatile"
7418     } else {
7419       $$emit$$"MEMBAR-volatile ! (empty encoding)"
7420     }
7421   %}
7422   ins_encode %{
7423     __ membar(Assembler::StoreLoad);
7424   %}
7425   ins_pipe(pipe_slow);
7426 %}
7427 
7428 instruct unnecessary_membar_volatile()
7429 %{
7430   match(MemBarVolatile);
7431   predicate(Matcher::post_store_load_barrier(n));
7432   ins_cost(0);
7433 
7434   size(0);
7435   format %{ "MEMBAR-volatile (unnecessary so empty encoding)" %}
7436   ins_encode();
7437   ins_pipe(empty);
7438 %}
7439 
7440 //----------Move Instructions--------------------------------------------------
7441 
7442 instruct castX2P(rRegP dst, rRegL src)
7443 %{
7444   match(Set dst (CastX2P src));
7445 
7446   format %{ "movq    $dst, $src\t# long->ptr" %}
7447   ins_encode(enc_copy_wide(dst, src));
7448   ins_pipe(ialu_reg_reg); // XXX
7449 %}
7450 
7451 instruct castP2X(rRegL dst, rRegP src)
7452 %{
7453   match(Set dst (CastP2X src));
7454 
7455   format %{ "movq    $dst, $src\t# ptr -> long" %}
7456   ins_encode(enc_copy_wide(dst, src));
7457   ins_pipe(ialu_reg_reg); // XXX
7458 %}
7459 
7460 
7461 // Convert oop pointer into compressed form
7462 instruct encodeHeapOop(rRegN dst, rRegP src, rFlagsReg cr) %{
7463   predicate(n->bottom_type()->make_ptr()->ptr() != TypePtr::NotNull);
7464   match(Set dst (EncodeP src));
7465   effect(KILL cr);
7466   format %{ "encode_heap_oop $dst,$src" %}
7467   ins_encode %{
7468     Register s = $src$$Register;
7469     Register d = $dst$$Register;
7470     if (s != d) {
7471       __ movq(d, s);
7472     }
7473     __ encode_heap_oop(d);
7474   %}
7475   ins_pipe(ialu_reg_long);
7476 %}
7477 
7478 instruct encodeHeapOop_not_null(rRegN dst, rRegP src, rFlagsReg cr) %{
7479   predicate(n->bottom_type()->make_ptr()->ptr() == TypePtr::NotNull);
7480   match(Set dst (EncodeP src));
7481   effect(KILL cr);
7482   format %{ "encode_heap_oop_not_null $dst,$src" %}
7483   ins_encode %{
7484     __ encode_heap_oop_not_null($dst$$Register, $src$$Register);
7485   %}
7486   ins_pipe(ialu_reg_long);
7487 %}
7488 
7489 instruct decodeHeapOop(rRegP dst, rRegN src, rFlagsReg cr) %{
7490   predicate(n->bottom_type()->is_oopptr()->ptr() != TypePtr::NotNull &&
7491             n->bottom_type()->is_oopptr()->ptr() != TypePtr::Constant);
7492   match(Set dst (DecodeN src));
7493   effect(KILL cr);
7494   format %{ "decode_heap_oop $dst,$src" %}
7495   ins_encode %{
7496     Register s = $src$$Register;
7497     Register d = $dst$$Register;
7498     if (s != d) {
7499       __ movq(d, s);
7500     }
7501     __ decode_heap_oop(d);
7502   %}
7503   ins_pipe(ialu_reg_long);
7504 %}
7505 
7506 instruct decodeHeapOop_not_null(rRegP dst, rRegN src, rFlagsReg cr) %{
7507   predicate(n->bottom_type()->is_oopptr()->ptr() == TypePtr::NotNull ||
7508             n->bottom_type()->is_oopptr()->ptr() == TypePtr::Constant);
7509   match(Set dst (DecodeN src));
7510   effect(KILL cr);
7511   format %{ "decode_heap_oop_not_null $dst,$src" %}
7512   ins_encode %{
7513     Register s = $src$$Register;
7514     Register d = $dst$$Register;
7515     if (s != d) {
7516       __ decode_heap_oop_not_null(d, s);
7517     } else {
7518       __ decode_heap_oop_not_null(d);
7519     }
7520   %}
7521   ins_pipe(ialu_reg_long);
7522 %}
7523 
7524 
7525 //----------Conditional Move---------------------------------------------------
7526 // Jump
7527 // dummy instruction for generating temp registers
7528 instruct jumpXtnd_offset(rRegL switch_val, immI2 shift, rRegI dest) %{
7529   match(Jump (LShiftL switch_val shift));
7530   ins_cost(350);
7531   predicate(false);
7532   effect(TEMP dest);
7533 
7534   format %{ "leaq    $dest, [$constantaddress]\n\t"
7535             "jmp     [$dest + $switch_val << $shift]\n\t" %}
7536   ins_encode %{
7537     // We could use jump(ArrayAddress) except that the macro assembler needs to use r10
7538     // to do that and the compiler is using that register as one it can allocate.
7539     // So we build it all by hand.
7540     // Address index(noreg, switch_reg, (Address::ScaleFactor)$shift$$constant);
7541     // ArrayAddress dispatch(table, index);
7542     Address dispatch($dest$$Register, $switch_val$$Register, (Address::ScaleFactor) $shift$$constant);
7543     __ lea($dest$$Register, $constantaddress);
7544     __ jmp(dispatch);
7545   %}
7546   ins_pipe(pipe_jmp);
7547 %}
7548 
7549 instruct jumpXtnd_addr(rRegL switch_val, immI2 shift, immL32 offset, rRegI dest) %{
7550   match(Jump (AddL (LShiftL switch_val shift) offset));
7551   ins_cost(350);
7552   effect(TEMP dest);
7553 
7554   format %{ "leaq    $dest, [$constantaddress]\n\t"
7555             "jmp     [$dest + $switch_val << $shift + $offset]\n\t" %}
7556   ins_encode %{
7557     // We could use jump(ArrayAddress) except that the macro assembler needs to use r10
7558     // to do that and the compiler is using that register as one it can allocate.
7559     // So we build it all by hand.
7560     // Address index(noreg, switch_reg, (Address::ScaleFactor) $shift$$constant, (int) $offset$$constant);
7561     // ArrayAddress dispatch(table, index);
7562     Address dispatch($dest$$Register, $switch_val$$Register, (Address::ScaleFactor) $shift$$constant, (int) $offset$$constant);
7563     __ lea($dest$$Register, $constantaddress);
7564     __ jmp(dispatch);
7565   %}
7566   ins_pipe(pipe_jmp);
7567 %}
7568 
7569 instruct jumpXtnd(rRegL switch_val, rRegI dest) %{
7570   match(Jump switch_val);
7571   ins_cost(350);
7572   effect(TEMP dest);
7573 
7574   format %{ "leaq    $dest, [$constantaddress]\n\t"
7575             "jmp     [$dest + $switch_val]\n\t" %}
7576   ins_encode %{
7577     // We could use jump(ArrayAddress) except that the macro assembler needs to use r10
7578     // to do that and the compiler is using that register as one it can allocate.
7579     // So we build it all by hand.
7580     // Address index(noreg, switch_reg, Address::times_1);
7581     // ArrayAddress dispatch(table, index);
7582     Address dispatch($dest$$Register, $switch_val$$Register, Address::times_1);
7583     __ lea($dest$$Register, $constantaddress);
7584     __ jmp(dispatch);
7585   %}
7586   ins_pipe(pipe_jmp);
7587 %}
7588 
7589 // Conditional move
7590 instruct cmovI_reg(rRegI dst, rRegI src, rFlagsReg cr, cmpOp cop)
7591 %{
7592   match(Set dst (CMoveI (Binary cop cr) (Binary dst src)));
7593 
7594   ins_cost(200); // XXX
7595   format %{ "cmovl$cop $dst, $src\t# signed, int" %}
7596   opcode(0x0F, 0x40);
7597   ins_encode(REX_reg_reg(dst, src), enc_cmov(cop), reg_reg(dst, src));
7598   ins_pipe(pipe_cmov_reg);
7599 %}
7600 
7601 instruct cmovI_regU(cmpOpU cop, rFlagsRegU cr, rRegI dst, rRegI src) %{
7602   match(Set dst (CMoveI (Binary cop cr) (Binary dst src)));
7603 
7604   ins_cost(200); // XXX
7605   format %{ "cmovl$cop $dst, $src\t# unsigned, int" %}
7606   opcode(0x0F, 0x40);
7607   ins_encode(REX_reg_reg(dst, src), enc_cmov(cop), reg_reg(dst, src));
7608   ins_pipe(pipe_cmov_reg);
7609 %}
7610 
7611 instruct cmovI_regUCF(cmpOpUCF cop, rFlagsRegUCF cr, rRegI dst, rRegI src) %{
7612   match(Set dst (CMoveI (Binary cop cr) (Binary dst src)));
7613   ins_cost(200);
7614   expand %{
7615     cmovI_regU(cop, cr, dst, src);
7616   %}
7617 %}
7618 
7619 // Conditional move
7620 instruct cmovI_mem(cmpOp cop, rFlagsReg cr, rRegI dst, memory src) %{
7621   match(Set dst (CMoveI (Binary cop cr) (Binary dst (LoadI src))));
7622 
7623   ins_cost(250); // XXX
7624   format %{ "cmovl$cop $dst, $src\t# signed, int" %}
7625   opcode(0x0F, 0x40);
7626   ins_encode(REX_reg_mem(dst, src), enc_cmov(cop), reg_mem(dst, src));
7627   ins_pipe(pipe_cmov_mem);
7628 %}
7629 
7630 // Conditional move
7631 instruct cmovI_memU(cmpOpU cop, rFlagsRegU cr, rRegI dst, memory src)
7632 %{
7633   match(Set dst (CMoveI (Binary cop cr) (Binary dst (LoadI src))));
7634 
7635   ins_cost(250); // XXX
7636   format %{ "cmovl$cop $dst, $src\t# unsigned, int" %}
7637   opcode(0x0F, 0x40);
7638   ins_encode(REX_reg_mem(dst, src), enc_cmov(cop), reg_mem(dst, src));
7639   ins_pipe(pipe_cmov_mem);
7640 %}
7641 
7642 instruct cmovI_memUCF(cmpOpUCF cop, rFlagsRegUCF cr, rRegI dst, memory src) %{
7643   match(Set dst (CMoveI (Binary cop cr) (Binary dst (LoadI src))));
7644   ins_cost(250);
7645   expand %{
7646     cmovI_memU(cop, cr, dst, src);
7647   %}
7648 %}
7649 
7650 // Conditional move
7651 instruct cmovN_reg(rRegN dst, rRegN src, rFlagsReg cr, cmpOp cop)
7652 %{
7653   match(Set dst (CMoveN (Binary cop cr) (Binary dst src)));
7654 
7655   ins_cost(200); // XXX
7656   format %{ "cmovl$cop $dst, $src\t# signed, compressed ptr" %}
7657   opcode(0x0F, 0x40);
7658   ins_encode(REX_reg_reg(dst, src), enc_cmov(cop), reg_reg(dst, src));
7659   ins_pipe(pipe_cmov_reg);
7660 %}
7661 
7662 // Conditional move
7663 instruct cmovN_regU(cmpOpU cop, rFlagsRegU cr, rRegN dst, rRegN src)
7664 %{
7665   match(Set dst (CMoveN (Binary cop cr) (Binary dst src)));
7666 
7667   ins_cost(200); // XXX
7668   format %{ "cmovl$cop $dst, $src\t# unsigned, compressed ptr" %}
7669   opcode(0x0F, 0x40);
7670   ins_encode(REX_reg_reg(dst, src), enc_cmov(cop), reg_reg(dst, src));
7671   ins_pipe(pipe_cmov_reg);
7672 %}
7673 
7674 instruct cmovN_regUCF(cmpOpUCF cop, rFlagsRegUCF cr, rRegN dst, rRegN src) %{
7675   match(Set dst (CMoveN (Binary cop cr) (Binary dst src)));
7676   ins_cost(200);
7677   expand %{
7678     cmovN_regU(cop, cr, dst, src);
7679   %}
7680 %}
7681 
7682 // Conditional move
7683 instruct cmovP_reg(rRegP dst, rRegP src, rFlagsReg cr, cmpOp cop)
7684 %{
7685   match(Set dst (CMoveP (Binary cop cr) (Binary dst src)));
7686 
7687   ins_cost(200); // XXX
7688   format %{ "cmovq$cop $dst, $src\t# signed, ptr" %}
7689   opcode(0x0F, 0x40);
7690   ins_encode(REX_reg_reg_wide(dst, src), enc_cmov(cop), reg_reg(dst, src));
7691   ins_pipe(pipe_cmov_reg);  // XXX
7692 %}
7693 
7694 // Conditional move
7695 instruct cmovP_regU(cmpOpU cop, rFlagsRegU cr, rRegP dst, rRegP src)
7696 %{
7697   match(Set dst (CMoveP (Binary cop cr) (Binary dst src)));
7698 
7699   ins_cost(200); // XXX
7700   format %{ "cmovq$cop $dst, $src\t# unsigned, ptr" %}
7701   opcode(0x0F, 0x40);
7702   ins_encode(REX_reg_reg_wide(dst, src), enc_cmov(cop), reg_reg(dst, src));
7703   ins_pipe(pipe_cmov_reg); // XXX
7704 %}
7705 
7706 instruct cmovP_regUCF(cmpOpUCF cop, rFlagsRegUCF cr, rRegP dst, rRegP src) %{
7707   match(Set dst (CMoveP (Binary cop cr) (Binary dst src)));
7708   ins_cost(200);
7709   expand %{
7710     cmovP_regU(cop, cr, dst, src);
7711   %}
7712 %}
7713 
7714 // DISABLED: Requires the ADLC to emit a bottom_type call that
7715 // correctly meets the two pointer arguments; one is an incoming
7716 // register but the other is a memory operand.  ALSO appears to
7717 // be buggy with implicit null checks.
7718 //
7719 //// Conditional move
7720 //instruct cmovP_mem(cmpOp cop, rFlagsReg cr, rRegP dst, memory src)
7721 //%{
7722 //  match(Set dst (CMoveP (Binary cop cr) (Binary dst (LoadP src))));
7723 //  ins_cost(250);
7724 //  format %{ "CMOV$cop $dst,$src\t# ptr" %}
7725 //  opcode(0x0F,0x40);
7726 //  ins_encode( enc_cmov(cop), reg_mem( dst, src ) );
7727 //  ins_pipe( pipe_cmov_mem );
7728 //%}
7729 //
7730 //// Conditional move
7731 //instruct cmovP_memU(cmpOpU cop, rFlagsRegU cr, rRegP dst, memory src)
7732 //%{
7733 //  match(Set dst (CMoveP (Binary cop cr) (Binary dst (LoadP src))));
7734 //  ins_cost(250);
7735 //  format %{ "CMOV$cop $dst,$src\t# ptr" %}
7736 //  opcode(0x0F,0x40);
7737 //  ins_encode( enc_cmov(cop), reg_mem( dst, src ) );
7738 //  ins_pipe( pipe_cmov_mem );
7739 //%}
7740 
7741 instruct cmovL_reg(cmpOp cop, rFlagsReg cr, rRegL dst, rRegL src)
7742 %{
7743   match(Set dst (CMoveL (Binary cop cr) (Binary dst src)));
7744 
7745   ins_cost(200); // XXX
7746   format %{ "cmovq$cop $dst, $src\t# signed, long" %}
7747   opcode(0x0F, 0x40);
7748   ins_encode(REX_reg_reg_wide(dst, src), enc_cmov(cop), reg_reg(dst, src));
7749   ins_pipe(pipe_cmov_reg);  // XXX
7750 %}
7751 
7752 instruct cmovL_mem(cmpOp cop, rFlagsReg cr, rRegL dst, memory src)
7753 %{
7754   match(Set dst (CMoveL (Binary cop cr) (Binary dst (LoadL src))));
7755 
7756   ins_cost(200); // XXX
7757   format %{ "cmovq$cop $dst, $src\t# signed, long" %}
7758   opcode(0x0F, 0x40);
7759   ins_encode(REX_reg_mem_wide(dst, src), enc_cmov(cop), reg_mem(dst, src));
7760   ins_pipe(pipe_cmov_mem);  // XXX
7761 %}
7762 
7763 instruct cmovL_regU(cmpOpU cop, rFlagsRegU cr, rRegL dst, rRegL src)
7764 %{
7765   match(Set dst (CMoveL (Binary cop cr) (Binary dst src)));
7766 
7767   ins_cost(200); // XXX
7768   format %{ "cmovq$cop $dst, $src\t# unsigned, long" %}
7769   opcode(0x0F, 0x40);
7770   ins_encode(REX_reg_reg_wide(dst, src), enc_cmov(cop), reg_reg(dst, src));
7771   ins_pipe(pipe_cmov_reg); // XXX
7772 %}
7773 
7774 instruct cmovL_regUCF(cmpOpUCF cop, rFlagsRegUCF cr, rRegL dst, rRegL src) %{
7775   match(Set dst (CMoveL (Binary cop cr) (Binary dst src)));
7776   ins_cost(200);
7777   expand %{
7778     cmovL_regU(cop, cr, dst, src);
7779   %}
7780 %}
7781 
7782 instruct cmovL_memU(cmpOpU cop, rFlagsRegU cr, rRegL dst, memory src)
7783 %{
7784   match(Set dst (CMoveL (Binary cop cr) (Binary dst (LoadL src))));
7785 
7786   ins_cost(200); // XXX
7787   format %{ "cmovq$cop $dst, $src\t# unsigned, long" %}
7788   opcode(0x0F, 0x40);
7789   ins_encode(REX_reg_mem_wide(dst, src), enc_cmov(cop), reg_mem(dst, src));
7790   ins_pipe(pipe_cmov_mem); // XXX
7791 %}
7792 
7793 instruct cmovL_memUCF(cmpOpUCF cop, rFlagsRegUCF cr, rRegL dst, memory src) %{
7794   match(Set dst (CMoveL (Binary cop cr) (Binary dst (LoadL src))));
7795   ins_cost(200);
7796   expand %{
7797     cmovL_memU(cop, cr, dst, src);
7798   %}
7799 %}
7800 
7801 instruct cmovF_reg(cmpOp cop, rFlagsReg cr, regF dst, regF src)
7802 %{
7803   match(Set dst (CMoveF (Binary cop cr) (Binary dst src)));
7804 
7805   ins_cost(200); // XXX
7806   format %{ "jn$cop    skip\t# signed cmove float\n\t"
7807             "movss     $dst, $src\n"
7808     "skip:" %}
7809   ins_encode(enc_cmovf_branch(cop, dst, src));
7810   ins_pipe(pipe_slow);
7811 %}
7812 
7813 // instruct cmovF_mem(cmpOp cop, rFlagsReg cr, regF dst, memory src)
7814 // %{
7815 //   match(Set dst (CMoveF (Binary cop cr) (Binary dst (LoadL src))));
7816 
7817 //   ins_cost(200); // XXX
7818 //   format %{ "jn$cop    skip\t# signed cmove float\n\t"
7819 //             "movss     $dst, $src\n"
7820 //     "skip:" %}
7821 //   ins_encode(enc_cmovf_mem_branch(cop, dst, src));
7822 //   ins_pipe(pipe_slow);
7823 // %}
7824 
7825 instruct cmovF_regU(cmpOpU cop, rFlagsRegU cr, regF dst, regF src)
7826 %{
7827   match(Set dst (CMoveF (Binary cop cr) (Binary dst src)));
7828 
7829   ins_cost(200); // XXX
7830   format %{ "jn$cop    skip\t# unsigned cmove float\n\t"
7831             "movss     $dst, $src\n"
7832     "skip:" %}
7833   ins_encode(enc_cmovf_branch(cop, dst, src));
7834   ins_pipe(pipe_slow);
7835 %}
7836 
7837 instruct cmovF_regUCF(cmpOpUCF cop, rFlagsRegUCF cr, regF dst, regF src) %{
7838   match(Set dst (CMoveF (Binary cop cr) (Binary dst src)));
7839   ins_cost(200);
7840   expand %{
7841     cmovF_regU(cop, cr, dst, src);
7842   %}
7843 %}
7844 
7845 instruct cmovD_reg(cmpOp cop, rFlagsReg cr, regD dst, regD src)
7846 %{
7847   match(Set dst (CMoveD (Binary cop cr) (Binary dst src)));
7848 
7849   ins_cost(200); // XXX
7850   format %{ "jn$cop    skip\t# signed cmove double\n\t"
7851             "movsd     $dst, $src\n"
7852     "skip:" %}
7853   ins_encode(enc_cmovd_branch(cop, dst, src));
7854   ins_pipe(pipe_slow);
7855 %}
7856 
7857 instruct cmovD_regU(cmpOpU cop, rFlagsRegU cr, regD dst, regD src)
7858 %{
7859   match(Set dst (CMoveD (Binary cop cr) (Binary dst src)));
7860 
7861   ins_cost(200); // XXX
7862   format %{ "jn$cop    skip\t# unsigned cmove double\n\t"
7863             "movsd     $dst, $src\n"
7864     "skip:" %}
7865   ins_encode(enc_cmovd_branch(cop, dst, src));
7866   ins_pipe(pipe_slow);
7867 %}
7868 
7869 instruct cmovD_regUCF(cmpOpUCF cop, rFlagsRegUCF cr, regD dst, regD src) %{
7870   match(Set dst (CMoveD (Binary cop cr) (Binary dst src)));
7871   ins_cost(200);
7872   expand %{
7873     cmovD_regU(cop, cr, dst, src);
7874   %}
7875 %}
7876 
7877 //----------Arithmetic Instructions--------------------------------------------
7878 //----------Addition Instructions----------------------------------------------
7879 
7880 instruct addI_rReg(rRegI dst, rRegI src, rFlagsReg cr)
7881 %{
7882   match(Set dst (AddI dst src));
7883   effect(KILL cr);
7884 
7885   format %{ "addl    $dst, $src\t# int" %}
7886   opcode(0x03);
7887   ins_encode(REX_reg_reg(dst, src), OpcP, reg_reg(dst, src));
7888   ins_pipe(ialu_reg_reg);
7889 %}
7890 
7891 instruct addI_rReg_imm(rRegI dst, immI src, rFlagsReg cr)
7892 %{
7893   match(Set dst (AddI dst src));
7894   effect(KILL cr);
7895 
7896   format %{ "addl    $dst, $src\t# int" %}
7897   opcode(0x81, 0x00); /* /0 id */
7898   ins_encode(OpcSErm(dst, src), Con8or32(src));
7899   ins_pipe( ialu_reg );
7900 %}
7901 
7902 instruct addI_rReg_mem(rRegI dst, memory src, rFlagsReg cr)
7903 %{
7904   match(Set dst (AddI dst (LoadI src)));
7905   effect(KILL cr);
7906 
7907   ins_cost(125); // XXX
7908   format %{ "addl    $dst, $src\t# int" %}
7909   opcode(0x03);
7910   ins_encode(REX_reg_mem(dst, src), OpcP, reg_mem(dst, src));
7911   ins_pipe(ialu_reg_mem);
7912 %}
7913 
7914 instruct addI_mem_rReg(memory dst, rRegI src, rFlagsReg cr)
7915 %{
7916   match(Set dst (StoreI dst (AddI (LoadI dst) src)));
7917   effect(KILL cr);
7918 
7919   ins_cost(150); // XXX
7920   format %{ "addl    $dst, $src\t# int" %}
7921   opcode(0x01); /* Opcode 01 /r */
7922   ins_encode(REX_reg_mem(src, dst), OpcP, reg_mem(src, dst));
7923   ins_pipe(ialu_mem_reg);
7924 %}
7925 
7926 instruct addI_mem_imm(memory dst, immI src, rFlagsReg cr)
7927 %{
7928   match(Set dst (StoreI dst (AddI (LoadI dst) src)));
7929   effect(KILL cr);
7930 
7931   ins_cost(125); // XXX
7932   format %{ "addl    $dst, $src\t# int" %}
7933   opcode(0x81); /* Opcode 81 /0 id */
7934   ins_encode(REX_mem(dst), OpcSE(src), RM_opc_mem(0x00, dst), Con8or32(src));
7935   ins_pipe(ialu_mem_imm);
7936 %}
7937 
7938 instruct incI_rReg(rRegI dst, immI1 src, rFlagsReg cr)
7939 %{
7940   predicate(UseIncDec);
7941   match(Set dst (AddI dst src));
7942   effect(KILL cr);
7943 
7944   format %{ "incl    $dst\t# int" %}
7945   opcode(0xFF, 0x00); // FF /0
7946   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
7947   ins_pipe(ialu_reg);
7948 %}
7949 
7950 instruct incI_mem(memory dst, immI1 src, rFlagsReg cr)
7951 %{
7952   predicate(UseIncDec);
7953   match(Set dst (StoreI dst (AddI (LoadI dst) src)));
7954   effect(KILL cr);
7955 
7956   ins_cost(125); // XXX
7957   format %{ "incl    $dst\t# int" %}
7958   opcode(0xFF); /* Opcode FF /0 */
7959   ins_encode(REX_mem(dst), OpcP, RM_opc_mem(0x00, dst));
7960   ins_pipe(ialu_mem_imm);
7961 %}
7962 
7963 // XXX why does that use AddI
7964 instruct decI_rReg(rRegI dst, immI_M1 src, rFlagsReg cr)
7965 %{
7966   predicate(UseIncDec);
7967   match(Set dst (AddI dst src));
7968   effect(KILL cr);
7969 
7970   format %{ "decl    $dst\t# int" %}
7971   opcode(0xFF, 0x01); // FF /1
7972   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
7973   ins_pipe(ialu_reg);
7974 %}
7975 
7976 // XXX why does that use AddI
7977 instruct decI_mem(memory dst, immI_M1 src, rFlagsReg cr)
7978 %{
7979   predicate(UseIncDec);
7980   match(Set dst (StoreI dst (AddI (LoadI dst) src)));
7981   effect(KILL cr);
7982 
7983   ins_cost(125); // XXX
7984   format %{ "decl    $dst\t# int" %}
7985   opcode(0xFF); /* Opcode FF /1 */
7986   ins_encode(REX_mem(dst), OpcP, RM_opc_mem(0x01, dst));
7987   ins_pipe(ialu_mem_imm);
7988 %}
7989 
7990 instruct leaI_rReg_immI(rRegI dst, rRegI src0, immI src1)
7991 %{
7992   match(Set dst (AddI src0 src1));
7993 
7994   ins_cost(110);
7995   format %{ "addr32 leal $dst, [$src0 + $src1]\t# int" %}
7996   opcode(0x8D); /* 0x8D /r */
7997   ins_encode(Opcode(0x67), REX_reg_reg(dst, src0), OpcP, reg_lea(dst, src0, src1)); // XXX
7998   ins_pipe(ialu_reg_reg);
7999 %}
8000 
8001 instruct addL_rReg(rRegL dst, rRegL src, rFlagsReg cr)
8002 %{
8003   match(Set dst (AddL dst src));
8004   effect(KILL cr);
8005 
8006   format %{ "addq    $dst, $src\t# long" %}
8007   opcode(0x03);
8008   ins_encode(REX_reg_reg_wide(dst, src), OpcP, reg_reg(dst, src));
8009   ins_pipe(ialu_reg_reg);
8010 %}
8011 
8012 instruct addL_rReg_imm(rRegL dst, immL32 src, rFlagsReg cr)
8013 %{
8014   match(Set dst (AddL dst src));
8015   effect(KILL cr);
8016 
8017   format %{ "addq    $dst, $src\t# long" %}
8018   opcode(0x81, 0x00); /* /0 id */
8019   ins_encode(OpcSErm_wide(dst, src), Con8or32(src));
8020   ins_pipe( ialu_reg );
8021 %}
8022 
8023 instruct addL_rReg_mem(rRegL dst, memory src, rFlagsReg cr)
8024 %{
8025   match(Set dst (AddL dst (LoadL src)));
8026   effect(KILL cr);
8027 
8028   ins_cost(125); // XXX
8029   format %{ "addq    $dst, $src\t# long" %}
8030   opcode(0x03);
8031   ins_encode(REX_reg_mem_wide(dst, src), OpcP, reg_mem(dst, src));
8032   ins_pipe(ialu_reg_mem);
8033 %}
8034 
8035 instruct addL_mem_rReg(memory dst, rRegL src, rFlagsReg cr)
8036 %{
8037   match(Set dst (StoreL dst (AddL (LoadL dst) src)));
8038   effect(KILL cr);
8039 
8040   ins_cost(150); // XXX
8041   format %{ "addq    $dst, $src\t# long" %}
8042   opcode(0x01); /* Opcode 01 /r */
8043   ins_encode(REX_reg_mem_wide(src, dst), OpcP, reg_mem(src, dst));
8044   ins_pipe(ialu_mem_reg);
8045 %}
8046 
8047 instruct addL_mem_imm(memory dst, immL32 src, rFlagsReg cr)
8048 %{
8049   match(Set dst (StoreL dst (AddL (LoadL dst) src)));
8050   effect(KILL cr);
8051 
8052   ins_cost(125); // XXX
8053   format %{ "addq    $dst, $src\t# long" %}
8054   opcode(0x81); /* Opcode 81 /0 id */
8055   ins_encode(REX_mem_wide(dst),
8056              OpcSE(src), RM_opc_mem(0x00, dst), Con8or32(src));
8057   ins_pipe(ialu_mem_imm);
8058 %}
8059 
8060 instruct incL_rReg(rRegI dst, immL1 src, rFlagsReg cr)
8061 %{
8062   predicate(UseIncDec);
8063   match(Set dst (AddL dst src));
8064   effect(KILL cr);
8065 
8066   format %{ "incq    $dst\t# long" %}
8067   opcode(0xFF, 0x00); // FF /0
8068   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst));
8069   ins_pipe(ialu_reg);
8070 %}
8071 
8072 instruct incL_mem(memory dst, immL1 src, rFlagsReg cr)
8073 %{
8074   predicate(UseIncDec);
8075   match(Set dst (StoreL dst (AddL (LoadL dst) src)));
8076   effect(KILL cr);
8077 
8078   ins_cost(125); // XXX
8079   format %{ "incq    $dst\t# long" %}
8080   opcode(0xFF); /* Opcode FF /0 */
8081   ins_encode(REX_mem_wide(dst), OpcP, RM_opc_mem(0x00, dst));
8082   ins_pipe(ialu_mem_imm);
8083 %}
8084 
8085 // XXX why does that use AddL
8086 instruct decL_rReg(rRegL dst, immL_M1 src, rFlagsReg cr)
8087 %{
8088   predicate(UseIncDec);
8089   match(Set dst (AddL dst src));
8090   effect(KILL cr);
8091 
8092   format %{ "decq    $dst\t# long" %}
8093   opcode(0xFF, 0x01); // FF /1
8094   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst));
8095   ins_pipe(ialu_reg);
8096 %}
8097 
8098 // XXX why does that use AddL
8099 instruct decL_mem(memory dst, immL_M1 src, rFlagsReg cr)
8100 %{
8101   predicate(UseIncDec);
8102   match(Set dst (StoreL dst (AddL (LoadL dst) src)));
8103   effect(KILL cr);
8104 
8105   ins_cost(125); // XXX
8106   format %{ "decq    $dst\t# long" %}
8107   opcode(0xFF); /* Opcode FF /1 */
8108   ins_encode(REX_mem_wide(dst), OpcP, RM_opc_mem(0x01, dst));
8109   ins_pipe(ialu_mem_imm);
8110 %}
8111 
8112 instruct leaL_rReg_immL(rRegL dst, rRegL src0, immL32 src1)
8113 %{
8114   match(Set dst (AddL src0 src1));
8115 
8116   ins_cost(110);
8117   format %{ "leaq    $dst, [$src0 + $src1]\t# long" %}
8118   opcode(0x8D); /* 0x8D /r */
8119   ins_encode(REX_reg_reg_wide(dst, src0), OpcP, reg_lea(dst, src0, src1)); // XXX
8120   ins_pipe(ialu_reg_reg);
8121 %}
8122 
8123 instruct addP_rReg(rRegP dst, rRegL src, rFlagsReg cr)
8124 %{
8125   match(Set dst (AddP dst src));
8126   effect(KILL cr);
8127 
8128   format %{ "addq    $dst, $src\t# ptr" %}
8129   opcode(0x03);
8130   ins_encode(REX_reg_reg_wide(dst, src), OpcP, reg_reg(dst, src));
8131   ins_pipe(ialu_reg_reg);
8132 %}
8133 
8134 instruct addP_rReg_imm(rRegP dst, immL32 src, rFlagsReg cr)
8135 %{
8136   match(Set dst (AddP dst src));
8137   effect(KILL cr);
8138 
8139   format %{ "addq    $dst, $src\t# ptr" %}
8140   opcode(0x81, 0x00); /* /0 id */
8141   ins_encode(OpcSErm_wide(dst, src), Con8or32(src));
8142   ins_pipe( ialu_reg );
8143 %}
8144 
8145 // XXX addP mem ops ????
8146 
8147 instruct leaP_rReg_imm(rRegP dst, rRegP src0, immL32 src1)
8148 %{
8149   match(Set dst (AddP src0 src1));
8150 
8151   ins_cost(110);
8152   format %{ "leaq    $dst, [$src0 + $src1]\t# ptr" %}
8153   opcode(0x8D); /* 0x8D /r */
8154   ins_encode(REX_reg_reg_wide(dst, src0), OpcP, reg_lea(dst, src0, src1));// XXX
8155   ins_pipe(ialu_reg_reg);
8156 %}
8157 
8158 instruct checkCastPP(rRegP dst)
8159 %{
8160   match(Set dst (CheckCastPP dst));
8161 
8162   size(0);
8163   format %{ "# checkcastPP of $dst" %}
8164   ins_encode(/* empty encoding */);
8165   ins_pipe(empty);
8166 %}
8167 
8168 instruct castPP(rRegP dst)
8169 %{
8170   match(Set dst (CastPP dst));
8171 
8172   size(0);
8173   format %{ "# castPP of $dst" %}
8174   ins_encode(/* empty encoding */);
8175   ins_pipe(empty);
8176 %}
8177 
8178 instruct castII(rRegI dst)
8179 %{
8180   match(Set dst (CastII dst));
8181 
8182   size(0);
8183   format %{ "# castII of $dst" %}
8184   ins_encode(/* empty encoding */);
8185   ins_cost(0);
8186   ins_pipe(empty);
8187 %}
8188 
8189 // LoadP-locked same as a regular LoadP when used with compare-swap
8190 instruct loadPLocked(rRegP dst, memory mem)
8191 %{
8192   match(Set dst (LoadPLocked mem));
8193 
8194   ins_cost(125); // XXX
8195   format %{ "movq    $dst, $mem\t# ptr locked" %}
8196   opcode(0x8B);
8197   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
8198   ins_pipe(ialu_reg_mem); // XXX
8199 %}
8200 
8201 // LoadL-locked - same as a regular LoadL when used with compare-swap
8202 instruct loadLLocked(rRegL dst, memory mem)
8203 %{
8204   match(Set dst (LoadLLocked mem));
8205 
8206   ins_cost(125); // XXX
8207   format %{ "movq    $dst, $mem\t# long locked" %}
8208   opcode(0x8B);
8209   ins_encode(REX_reg_mem_wide(dst, mem), OpcP, reg_mem(dst, mem));
8210   ins_pipe(ialu_reg_mem); // XXX
8211 %}
8212 
8213 // Conditional-store of the updated heap-top.
8214 // Used during allocation of the shared heap.
8215 // Sets flags (EQ) on success.  Implemented with a CMPXCHG on Intel.
8216 
8217 instruct storePConditional(memory heap_top_ptr,
8218                            rax_RegP oldval, rRegP newval,
8219                            rFlagsReg cr)
8220 %{
8221   match(Set cr (StorePConditional heap_top_ptr (Binary oldval newval)));
8222 
8223   format %{ "cmpxchgq $heap_top_ptr, $newval\t# (ptr) "
8224             "If rax == $heap_top_ptr then store $newval into $heap_top_ptr" %}
8225   opcode(0x0F, 0xB1);
8226   ins_encode(lock_prefix,
8227              REX_reg_mem_wide(newval, heap_top_ptr),
8228              OpcP, OpcS,
8229              reg_mem(newval, heap_top_ptr));
8230   ins_pipe(pipe_cmpxchg);
8231 %}
8232 
8233 // Conditional-store of an int value.
8234 // ZF flag is set on success, reset otherwise.  Implemented with a CMPXCHG.
8235 instruct storeIConditional(memory mem, rax_RegI oldval, rRegI newval, rFlagsReg cr)
8236 %{
8237   match(Set cr (StoreIConditional mem (Binary oldval newval)));
8238   effect(KILL oldval);
8239 
8240   format %{ "cmpxchgl $mem, $newval\t# If rax == $mem then store $newval into $mem" %}
8241   opcode(0x0F, 0xB1);
8242   ins_encode(lock_prefix,
8243              REX_reg_mem(newval, mem),
8244              OpcP, OpcS,
8245              reg_mem(newval, mem));
8246   ins_pipe(pipe_cmpxchg);
8247 %}
8248 
8249 // Conditional-store of a long value.
8250 // ZF flag is set on success, reset otherwise.  Implemented with a CMPXCHG.
8251 instruct storeLConditional(memory mem, rax_RegL oldval, rRegL newval, rFlagsReg cr)
8252 %{
8253   match(Set cr (StoreLConditional mem (Binary oldval newval)));
8254   effect(KILL oldval);
8255 
8256   format %{ "cmpxchgq $mem, $newval\t# If rax == $mem then store $newval into $mem" %}
8257   opcode(0x0F, 0xB1);
8258   ins_encode(lock_prefix,
8259              REX_reg_mem_wide(newval, mem),
8260              OpcP, OpcS,
8261              reg_mem(newval, mem));
8262   ins_pipe(pipe_cmpxchg);
8263 %}
8264 
8265 
8266 // XXX No flag versions for CompareAndSwap{P,I,L} because matcher can't match them
8267 instruct compareAndSwapP(rRegI res,
8268                          memory mem_ptr,
8269                          rax_RegP oldval, rRegP newval,
8270                          rFlagsReg cr)
8271 %{
8272   match(Set res (CompareAndSwapP mem_ptr (Binary oldval newval)));
8273   effect(KILL cr, KILL oldval);
8274 
8275   format %{ "cmpxchgq $mem_ptr,$newval\t# "
8276             "If rax == $mem_ptr then store $newval into $mem_ptr\n\t"
8277             "sete    $res\n\t"
8278             "movzbl  $res, $res" %}
8279   opcode(0x0F, 0xB1);
8280   ins_encode(lock_prefix,
8281              REX_reg_mem_wide(newval, mem_ptr),
8282              OpcP, OpcS,
8283              reg_mem(newval, mem_ptr),
8284              REX_breg(res), Opcode(0x0F), Opcode(0x94), reg(res), // sete
8285              REX_reg_breg(res, res), // movzbl
8286              Opcode(0xF), Opcode(0xB6), reg_reg(res, res));
8287   ins_pipe( pipe_cmpxchg );
8288 %}
8289 
8290 instruct compareAndSwapL(rRegI res,
8291                          memory mem_ptr,
8292                          rax_RegL oldval, rRegL newval,
8293                          rFlagsReg cr)
8294 %{
8295   match(Set res (CompareAndSwapL mem_ptr (Binary oldval newval)));
8296   effect(KILL cr, KILL oldval);
8297 
8298   format %{ "cmpxchgq $mem_ptr,$newval\t# "
8299             "If rax == $mem_ptr then store $newval into $mem_ptr\n\t"
8300             "sete    $res\n\t"
8301             "movzbl  $res, $res" %}
8302   opcode(0x0F, 0xB1);
8303   ins_encode(lock_prefix,
8304              REX_reg_mem_wide(newval, mem_ptr),
8305              OpcP, OpcS,
8306              reg_mem(newval, mem_ptr),
8307              REX_breg(res), Opcode(0x0F), Opcode(0x94), reg(res), // sete
8308              REX_reg_breg(res, res), // movzbl
8309              Opcode(0xF), Opcode(0xB6), reg_reg(res, res));
8310   ins_pipe( pipe_cmpxchg );
8311 %}
8312 
8313 instruct compareAndSwapI(rRegI res,
8314                          memory mem_ptr,
8315                          rax_RegI oldval, rRegI newval,
8316                          rFlagsReg cr)
8317 %{
8318   match(Set res (CompareAndSwapI mem_ptr (Binary oldval newval)));
8319   effect(KILL cr, KILL oldval);
8320 
8321   format %{ "cmpxchgl $mem_ptr,$newval\t# "
8322             "If rax == $mem_ptr then store $newval into $mem_ptr\n\t"
8323             "sete    $res\n\t"
8324             "movzbl  $res, $res" %}
8325   opcode(0x0F, 0xB1);
8326   ins_encode(lock_prefix,
8327              REX_reg_mem(newval, mem_ptr),
8328              OpcP, OpcS,
8329              reg_mem(newval, mem_ptr),
8330              REX_breg(res), Opcode(0x0F), Opcode(0x94), reg(res), // sete
8331              REX_reg_breg(res, res), // movzbl
8332              Opcode(0xF), Opcode(0xB6), reg_reg(res, res));
8333   ins_pipe( pipe_cmpxchg );
8334 %}
8335 
8336 
8337 instruct compareAndSwapN(rRegI res,
8338                           memory mem_ptr,
8339                           rax_RegN oldval, rRegN newval,
8340                           rFlagsReg cr) %{
8341   match(Set res (CompareAndSwapN mem_ptr (Binary oldval newval)));
8342   effect(KILL cr, KILL oldval);
8343 
8344   format %{ "cmpxchgl $mem_ptr,$newval\t# "
8345             "If rax == $mem_ptr then store $newval into $mem_ptr\n\t"
8346             "sete    $res\n\t"
8347             "movzbl  $res, $res" %}
8348   opcode(0x0F, 0xB1);
8349   ins_encode(lock_prefix,
8350              REX_reg_mem(newval, mem_ptr),
8351              OpcP, OpcS,
8352              reg_mem(newval, mem_ptr),
8353              REX_breg(res), Opcode(0x0F), Opcode(0x94), reg(res), // sete
8354              REX_reg_breg(res, res), // movzbl
8355              Opcode(0xF), Opcode(0xB6), reg_reg(res, res));
8356   ins_pipe( pipe_cmpxchg );
8357 %}
8358 
8359 //----------Subtraction Instructions-------------------------------------------
8360 
8361 // Integer Subtraction Instructions
8362 instruct subI_rReg(rRegI dst, rRegI src, rFlagsReg cr)
8363 %{
8364   match(Set dst (SubI dst src));
8365   effect(KILL cr);
8366 
8367   format %{ "subl    $dst, $src\t# int" %}
8368   opcode(0x2B);
8369   ins_encode(REX_reg_reg(dst, src), OpcP, reg_reg(dst, src));
8370   ins_pipe(ialu_reg_reg);
8371 %}
8372 
8373 instruct subI_rReg_imm(rRegI dst, immI src, rFlagsReg cr)
8374 %{
8375   match(Set dst (SubI dst src));
8376   effect(KILL cr);
8377 
8378   format %{ "subl    $dst, $src\t# int" %}
8379   opcode(0x81, 0x05);  /* Opcode 81 /5 */
8380   ins_encode(OpcSErm(dst, src), Con8or32(src));
8381   ins_pipe(ialu_reg);
8382 %}
8383 
8384 instruct subI_rReg_mem(rRegI dst, memory src, rFlagsReg cr)
8385 %{
8386   match(Set dst (SubI dst (LoadI src)));
8387   effect(KILL cr);
8388 
8389   ins_cost(125);
8390   format %{ "subl    $dst, $src\t# int" %}
8391   opcode(0x2B);
8392   ins_encode(REX_reg_mem(dst, src), OpcP, reg_mem(dst, src));
8393   ins_pipe(ialu_reg_mem);
8394 %}
8395 
8396 instruct subI_mem_rReg(memory dst, rRegI src, rFlagsReg cr)
8397 %{
8398   match(Set dst (StoreI dst (SubI (LoadI dst) src)));
8399   effect(KILL cr);
8400 
8401   ins_cost(150);
8402   format %{ "subl    $dst, $src\t# int" %}
8403   opcode(0x29); /* Opcode 29 /r */
8404   ins_encode(REX_reg_mem(src, dst), OpcP, reg_mem(src, dst));
8405   ins_pipe(ialu_mem_reg);
8406 %}
8407 
8408 instruct subI_mem_imm(memory dst, immI src, rFlagsReg cr)
8409 %{
8410   match(Set dst (StoreI dst (SubI (LoadI dst) src)));
8411   effect(KILL cr);
8412 
8413   ins_cost(125); // XXX
8414   format %{ "subl    $dst, $src\t# int" %}
8415   opcode(0x81); /* Opcode 81 /5 id */
8416   ins_encode(REX_mem(dst), OpcSE(src), RM_opc_mem(0x05, dst), Con8or32(src));
8417   ins_pipe(ialu_mem_imm);
8418 %}
8419 
8420 instruct subL_rReg(rRegL dst, rRegL src, rFlagsReg cr)
8421 %{
8422   match(Set dst (SubL dst src));
8423   effect(KILL cr);
8424 
8425   format %{ "subq    $dst, $src\t# long" %}
8426   opcode(0x2B);
8427   ins_encode(REX_reg_reg_wide(dst, src), OpcP, reg_reg(dst, src));
8428   ins_pipe(ialu_reg_reg);
8429 %}
8430 
8431 instruct subL_rReg_imm(rRegI dst, immL32 src, rFlagsReg cr)
8432 %{
8433   match(Set dst (SubL dst src));
8434   effect(KILL cr);
8435 
8436   format %{ "subq    $dst, $src\t# long" %}
8437   opcode(0x81, 0x05);  /* Opcode 81 /5 */
8438   ins_encode(OpcSErm_wide(dst, src), Con8or32(src));
8439   ins_pipe(ialu_reg);
8440 %}
8441 
8442 instruct subL_rReg_mem(rRegL dst, memory src, rFlagsReg cr)
8443 %{
8444   match(Set dst (SubL dst (LoadL src)));
8445   effect(KILL cr);
8446 
8447   ins_cost(125);
8448   format %{ "subq    $dst, $src\t# long" %}
8449   opcode(0x2B);
8450   ins_encode(REX_reg_mem_wide(dst, src), OpcP, reg_mem(dst, src));
8451   ins_pipe(ialu_reg_mem);
8452 %}
8453 
8454 instruct subL_mem_rReg(memory dst, rRegL src, rFlagsReg cr)
8455 %{
8456   match(Set dst (StoreL dst (SubL (LoadL dst) src)));
8457   effect(KILL cr);
8458 
8459   ins_cost(150);
8460   format %{ "subq    $dst, $src\t# long" %}
8461   opcode(0x29); /* Opcode 29 /r */
8462   ins_encode(REX_reg_mem_wide(src, dst), OpcP, reg_mem(src, dst));
8463   ins_pipe(ialu_mem_reg);
8464 %}
8465 
8466 instruct subL_mem_imm(memory dst, immL32 src, rFlagsReg cr)
8467 %{
8468   match(Set dst (StoreL dst (SubL (LoadL dst) src)));
8469   effect(KILL cr);
8470 
8471   ins_cost(125); // XXX
8472   format %{ "subq    $dst, $src\t# long" %}
8473   opcode(0x81); /* Opcode 81 /5 id */
8474   ins_encode(REX_mem_wide(dst),
8475              OpcSE(src), RM_opc_mem(0x05, dst), Con8or32(src));
8476   ins_pipe(ialu_mem_imm);
8477 %}
8478 
8479 // Subtract from a pointer
8480 // XXX hmpf???
8481 instruct subP_rReg(rRegP dst, rRegI src, immI0 zero, rFlagsReg cr)
8482 %{
8483   match(Set dst (AddP dst (SubI zero src)));
8484   effect(KILL cr);
8485 
8486   format %{ "subq    $dst, $src\t# ptr - int" %}
8487   opcode(0x2B);
8488   ins_encode(REX_reg_reg_wide(dst, src), OpcP, reg_reg(dst, src));
8489   ins_pipe(ialu_reg_reg);
8490 %}
8491 
8492 instruct negI_rReg(rRegI dst, immI0 zero, rFlagsReg cr)
8493 %{
8494   match(Set dst (SubI zero dst));
8495   effect(KILL cr);
8496 
8497   format %{ "negl    $dst\t# int" %}
8498   opcode(0xF7, 0x03);  // Opcode F7 /3
8499   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
8500   ins_pipe(ialu_reg);
8501 %}
8502 
8503 instruct negI_mem(memory dst, immI0 zero, rFlagsReg cr)
8504 %{
8505   match(Set dst (StoreI dst (SubI zero (LoadI dst))));
8506   effect(KILL cr);
8507 
8508   format %{ "negl    $dst\t# int" %}
8509   opcode(0xF7, 0x03);  // Opcode F7 /3
8510   ins_encode(REX_mem(dst), OpcP, RM_opc_mem(secondary, dst));
8511   ins_pipe(ialu_reg);
8512 %}
8513 
8514 instruct negL_rReg(rRegL dst, immL0 zero, rFlagsReg cr)
8515 %{
8516   match(Set dst (SubL zero dst));
8517   effect(KILL cr);
8518 
8519   format %{ "negq    $dst\t# long" %}
8520   opcode(0xF7, 0x03);  // Opcode F7 /3
8521   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst));
8522   ins_pipe(ialu_reg);
8523 %}
8524 
8525 instruct negL_mem(memory dst, immL0 zero, rFlagsReg cr)
8526 %{
8527   match(Set dst (StoreL dst (SubL zero (LoadL dst))));
8528   effect(KILL cr);
8529 
8530   format %{ "negq    $dst\t# long" %}
8531   opcode(0xF7, 0x03);  // Opcode F7 /3
8532   ins_encode(REX_mem_wide(dst), OpcP, RM_opc_mem(secondary, dst));
8533   ins_pipe(ialu_reg);
8534 %}
8535 
8536 
8537 //----------Multiplication/Division Instructions-------------------------------
8538 // Integer Multiplication Instructions
8539 // Multiply Register
8540 
8541 instruct mulI_rReg(rRegI dst, rRegI src, rFlagsReg cr)
8542 %{
8543   match(Set dst (MulI dst src));
8544   effect(KILL cr);
8545 
8546   ins_cost(300);
8547   format %{ "imull   $dst, $src\t# int" %}
8548   opcode(0x0F, 0xAF);
8549   ins_encode(REX_reg_reg(dst, src), OpcP, OpcS, reg_reg(dst, src));
8550   ins_pipe(ialu_reg_reg_alu0);
8551 %}
8552 
8553 instruct mulI_rReg_imm(rRegI dst, rRegI src, immI imm, rFlagsReg cr)
8554 %{
8555   match(Set dst (MulI src imm));
8556   effect(KILL cr);
8557 
8558   ins_cost(300);
8559   format %{ "imull   $dst, $src, $imm\t# int" %}
8560   opcode(0x69); /* 69 /r id */
8561   ins_encode(REX_reg_reg(dst, src),
8562              OpcSE(imm), reg_reg(dst, src), Con8or32(imm));
8563   ins_pipe(ialu_reg_reg_alu0);
8564 %}
8565 
8566 instruct mulI_mem(rRegI dst, memory src, rFlagsReg cr)
8567 %{
8568   match(Set dst (MulI dst (LoadI src)));
8569   effect(KILL cr);
8570 
8571   ins_cost(350);
8572   format %{ "imull   $dst, $src\t# int" %}
8573   opcode(0x0F, 0xAF);
8574   ins_encode(REX_reg_mem(dst, src), OpcP, OpcS, reg_mem(dst, src));
8575   ins_pipe(ialu_reg_mem_alu0);
8576 %}
8577 
8578 instruct mulI_mem_imm(rRegI dst, memory src, immI imm, rFlagsReg cr)
8579 %{
8580   match(Set dst (MulI (LoadI src) imm));
8581   effect(KILL cr);
8582 
8583   ins_cost(300);
8584   format %{ "imull   $dst, $src, $imm\t# int" %}
8585   opcode(0x69); /* 69 /r id */
8586   ins_encode(REX_reg_mem(dst, src),
8587              OpcSE(imm), reg_mem(dst, src), Con8or32(imm));
8588   ins_pipe(ialu_reg_mem_alu0);
8589 %}
8590 
8591 instruct mulL_rReg(rRegL dst, rRegL src, rFlagsReg cr)
8592 %{
8593   match(Set dst (MulL dst src));
8594   effect(KILL cr);
8595 
8596   ins_cost(300);
8597   format %{ "imulq   $dst, $src\t# long" %}
8598   opcode(0x0F, 0xAF);
8599   ins_encode(REX_reg_reg_wide(dst, src), OpcP, OpcS, reg_reg(dst, src));
8600   ins_pipe(ialu_reg_reg_alu0);
8601 %}
8602 
8603 instruct mulL_rReg_imm(rRegL dst, rRegL src, immL32 imm, rFlagsReg cr)
8604 %{
8605   match(Set dst (MulL src imm));
8606   effect(KILL cr);
8607 
8608   ins_cost(300);
8609   format %{ "imulq   $dst, $src, $imm\t# long" %}
8610   opcode(0x69); /* 69 /r id */
8611   ins_encode(REX_reg_reg_wide(dst, src),
8612              OpcSE(imm), reg_reg(dst, src), Con8or32(imm));
8613   ins_pipe(ialu_reg_reg_alu0);
8614 %}
8615 
8616 instruct mulL_mem(rRegL dst, memory src, rFlagsReg cr)
8617 %{
8618   match(Set dst (MulL dst (LoadL src)));
8619   effect(KILL cr);
8620 
8621   ins_cost(350);
8622   format %{ "imulq   $dst, $src\t# long" %}
8623   opcode(0x0F, 0xAF);
8624   ins_encode(REX_reg_mem_wide(dst, src), OpcP, OpcS, reg_mem(dst, src));
8625   ins_pipe(ialu_reg_mem_alu0);
8626 %}
8627 
8628 instruct mulL_mem_imm(rRegL dst, memory src, immL32 imm, rFlagsReg cr)
8629 %{
8630   match(Set dst (MulL (LoadL src) imm));
8631   effect(KILL cr);
8632 
8633   ins_cost(300);
8634   format %{ "imulq   $dst, $src, $imm\t# long" %}
8635   opcode(0x69); /* 69 /r id */
8636   ins_encode(REX_reg_mem_wide(dst, src),
8637              OpcSE(imm), reg_mem(dst, src), Con8or32(imm));
8638   ins_pipe(ialu_reg_mem_alu0);
8639 %}
8640 
8641 instruct mulHiL_rReg(rdx_RegL dst, no_rax_RegL src, rax_RegL rax, rFlagsReg cr)
8642 %{
8643   match(Set dst (MulHiL src rax));
8644   effect(USE_KILL rax, KILL cr);
8645 
8646   ins_cost(300);
8647   format %{ "imulq   RDX:RAX, RAX, $src\t# mulhi" %}
8648   opcode(0xF7, 0x5); /* Opcode F7 /5 */
8649   ins_encode(REX_reg_wide(src), OpcP, reg_opc(src));
8650   ins_pipe(ialu_reg_reg_alu0);
8651 %}
8652 
8653 instruct divI_rReg(rax_RegI rax, rdx_RegI rdx, no_rax_rdx_RegI div,
8654                    rFlagsReg cr)
8655 %{
8656   match(Set rax (DivI rax div));
8657   effect(KILL rdx, KILL cr);
8658 
8659   ins_cost(30*100+10*100); // XXX
8660   format %{ "cmpl    rax, 0x80000000\t# idiv\n\t"
8661             "jne,s   normal\n\t"
8662             "xorl    rdx, rdx\n\t"
8663             "cmpl    $div, -1\n\t"
8664             "je,s    done\n"
8665     "normal: cdql\n\t"
8666             "idivl   $div\n"
8667     "done:"        %}
8668   opcode(0xF7, 0x7);  /* Opcode F7 /7 */
8669   ins_encode(cdql_enc(div), REX_reg(div), OpcP, reg_opc(div));
8670   ins_pipe(ialu_reg_reg_alu0);
8671 %}
8672 
8673 instruct divL_rReg(rax_RegL rax, rdx_RegL rdx, no_rax_rdx_RegL div,
8674                    rFlagsReg cr)
8675 %{
8676   match(Set rax (DivL rax div));
8677   effect(KILL rdx, KILL cr);
8678 
8679   ins_cost(30*100+10*100); // XXX
8680   format %{ "movq    rdx, 0x8000000000000000\t# ldiv\n\t"
8681             "cmpq    rax, rdx\n\t"
8682             "jne,s   normal\n\t"
8683             "xorl    rdx, rdx\n\t"
8684             "cmpq    $div, -1\n\t"
8685             "je,s    done\n"
8686     "normal: cdqq\n\t"
8687             "idivq   $div\n"
8688     "done:"        %}
8689   opcode(0xF7, 0x7);  /* Opcode F7 /7 */
8690   ins_encode(cdqq_enc(div), REX_reg_wide(div), OpcP, reg_opc(div));
8691   ins_pipe(ialu_reg_reg_alu0);
8692 %}
8693 
8694 // Integer DIVMOD with Register, both quotient and mod results
8695 instruct divModI_rReg_divmod(rax_RegI rax, rdx_RegI rdx, no_rax_rdx_RegI div,
8696                              rFlagsReg cr)
8697 %{
8698   match(DivModI rax div);
8699   effect(KILL cr);
8700 
8701   ins_cost(30*100+10*100); // XXX
8702   format %{ "cmpl    rax, 0x80000000\t# idiv\n\t"
8703             "jne,s   normal\n\t"
8704             "xorl    rdx, rdx\n\t"
8705             "cmpl    $div, -1\n\t"
8706             "je,s    done\n"
8707     "normal: cdql\n\t"
8708             "idivl   $div\n"
8709     "done:"        %}
8710   opcode(0xF7, 0x7);  /* Opcode F7 /7 */
8711   ins_encode(cdql_enc(div), REX_reg(div), OpcP, reg_opc(div));
8712   ins_pipe(pipe_slow);
8713 %}
8714 
8715 // Long DIVMOD with Register, both quotient and mod results
8716 instruct divModL_rReg_divmod(rax_RegL rax, rdx_RegL rdx, no_rax_rdx_RegL div,
8717                              rFlagsReg cr)
8718 %{
8719   match(DivModL rax div);
8720   effect(KILL cr);
8721 
8722   ins_cost(30*100+10*100); // XXX
8723   format %{ "movq    rdx, 0x8000000000000000\t# ldiv\n\t"
8724             "cmpq    rax, rdx\n\t"
8725             "jne,s   normal\n\t"
8726             "xorl    rdx, rdx\n\t"
8727             "cmpq    $div, -1\n\t"
8728             "je,s    done\n"
8729     "normal: cdqq\n\t"
8730             "idivq   $div\n"
8731     "done:"        %}
8732   opcode(0xF7, 0x7);  /* Opcode F7 /7 */
8733   ins_encode(cdqq_enc(div), REX_reg_wide(div), OpcP, reg_opc(div));
8734   ins_pipe(pipe_slow);
8735 %}
8736 
8737 //----------- DivL-By-Constant-Expansions--------------------------------------
8738 // DivI cases are handled by the compiler
8739 
8740 // Magic constant, reciprocal of 10
8741 instruct loadConL_0x6666666666666667(rRegL dst)
8742 %{
8743   effect(DEF dst);
8744 
8745   format %{ "movq    $dst, #0x666666666666667\t# Used in div-by-10" %}
8746   ins_encode(load_immL(dst, 0x6666666666666667));
8747   ins_pipe(ialu_reg);
8748 %}
8749 
8750 instruct mul_hi(rdx_RegL dst, no_rax_RegL src, rax_RegL rax, rFlagsReg cr)
8751 %{
8752   effect(DEF dst, USE src, USE_KILL rax, KILL cr);
8753 
8754   format %{ "imulq   rdx:rax, rax, $src\t# Used in div-by-10" %}
8755   opcode(0xF7, 0x5); /* Opcode F7 /5 */
8756   ins_encode(REX_reg_wide(src), OpcP, reg_opc(src));
8757   ins_pipe(ialu_reg_reg_alu0);
8758 %}
8759 
8760 instruct sarL_rReg_63(rRegL dst, rFlagsReg cr)
8761 %{
8762   effect(USE_DEF dst, KILL cr);
8763 
8764   format %{ "sarq    $dst, #63\t# Used in div-by-10" %}
8765   opcode(0xC1, 0x7); /* C1 /7 ib */
8766   ins_encode(reg_opc_imm_wide(dst, 0x3F));
8767   ins_pipe(ialu_reg);
8768 %}
8769 
8770 instruct sarL_rReg_2(rRegL dst, rFlagsReg cr)
8771 %{
8772   effect(USE_DEF dst, KILL cr);
8773 
8774   format %{ "sarq    $dst, #2\t# Used in div-by-10" %}
8775   opcode(0xC1, 0x7); /* C1 /7 ib */
8776   ins_encode(reg_opc_imm_wide(dst, 0x2));
8777   ins_pipe(ialu_reg);
8778 %}
8779 
8780 instruct divL_10(rdx_RegL dst, no_rax_RegL src, immL10 div)
8781 %{
8782   match(Set dst (DivL src div));
8783 
8784   ins_cost((5+8)*100);
8785   expand %{
8786     rax_RegL rax;                     // Killed temp
8787     rFlagsReg cr;                     // Killed
8788     loadConL_0x6666666666666667(rax); // movq  rax, 0x6666666666666667
8789     mul_hi(dst, src, rax, cr);        // mulq  rdx:rax <= rax * $src
8790     sarL_rReg_63(src, cr);            // sarq  src, 63
8791     sarL_rReg_2(dst, cr);             // sarq  rdx, 2
8792     subL_rReg(dst, src, cr);          // subl  rdx, src
8793   %}
8794 %}
8795 
8796 //-----------------------------------------------------------------------------
8797 
8798 instruct modI_rReg(rdx_RegI rdx, rax_RegI rax, no_rax_rdx_RegI div,
8799                    rFlagsReg cr)
8800 %{
8801   match(Set rdx (ModI rax div));
8802   effect(KILL rax, KILL cr);
8803 
8804   ins_cost(300); // XXX
8805   format %{ "cmpl    rax, 0x80000000\t# irem\n\t"
8806             "jne,s   normal\n\t"
8807             "xorl    rdx, rdx\n\t"
8808             "cmpl    $div, -1\n\t"
8809             "je,s    done\n"
8810     "normal: cdql\n\t"
8811             "idivl   $div\n"
8812     "done:"        %}
8813   opcode(0xF7, 0x7);  /* Opcode F7 /7 */
8814   ins_encode(cdql_enc(div), REX_reg(div), OpcP, reg_opc(div));
8815   ins_pipe(ialu_reg_reg_alu0);
8816 %}
8817 
8818 instruct modL_rReg(rdx_RegL rdx, rax_RegL rax, no_rax_rdx_RegL div,
8819                    rFlagsReg cr)
8820 %{
8821   match(Set rdx (ModL rax div));
8822   effect(KILL rax, KILL cr);
8823 
8824   ins_cost(300); // XXX
8825   format %{ "movq    rdx, 0x8000000000000000\t# lrem\n\t"
8826             "cmpq    rax, rdx\n\t"
8827             "jne,s   normal\n\t"
8828             "xorl    rdx, rdx\n\t"
8829             "cmpq    $div, -1\n\t"
8830             "je,s    done\n"
8831     "normal: cdqq\n\t"
8832             "idivq   $div\n"
8833     "done:"        %}
8834   opcode(0xF7, 0x7);  /* Opcode F7 /7 */
8835   ins_encode(cdqq_enc(div), REX_reg_wide(div), OpcP, reg_opc(div));
8836   ins_pipe(ialu_reg_reg_alu0);
8837 %}
8838 
8839 // Integer Shift Instructions
8840 // Shift Left by one
8841 instruct salI_rReg_1(rRegI dst, immI1 shift, rFlagsReg cr)
8842 %{
8843   match(Set dst (LShiftI dst shift));
8844   effect(KILL cr);
8845 
8846   format %{ "sall    $dst, $shift" %}
8847   opcode(0xD1, 0x4); /* D1 /4 */
8848   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
8849   ins_pipe(ialu_reg);
8850 %}
8851 
8852 // Shift Left by one
8853 instruct salI_mem_1(memory dst, immI1 shift, rFlagsReg cr)
8854 %{
8855   match(Set dst (StoreI dst (LShiftI (LoadI dst) shift)));
8856   effect(KILL cr);
8857 
8858   format %{ "sall    $dst, $shift\t" %}
8859   opcode(0xD1, 0x4); /* D1 /4 */
8860   ins_encode(REX_mem(dst), OpcP, RM_opc_mem(secondary, dst));
8861   ins_pipe(ialu_mem_imm);
8862 %}
8863 
8864 // Shift Left by 8-bit immediate
8865 instruct salI_rReg_imm(rRegI dst, immI8 shift, rFlagsReg cr)
8866 %{
8867   match(Set dst (LShiftI dst shift));
8868   effect(KILL cr);
8869 
8870   format %{ "sall    $dst, $shift" %}
8871   opcode(0xC1, 0x4); /* C1 /4 ib */
8872   ins_encode(reg_opc_imm(dst, shift));
8873   ins_pipe(ialu_reg);
8874 %}
8875 
8876 // Shift Left by 8-bit immediate
8877 instruct salI_mem_imm(memory dst, immI8 shift, rFlagsReg cr)
8878 %{
8879   match(Set dst (StoreI dst (LShiftI (LoadI dst) shift)));
8880   effect(KILL cr);
8881 
8882   format %{ "sall    $dst, $shift" %}
8883   opcode(0xC1, 0x4); /* C1 /4 ib */
8884   ins_encode(REX_mem(dst), OpcP, RM_opc_mem(secondary, dst), Con8or32(shift));
8885   ins_pipe(ialu_mem_imm);
8886 %}
8887 
8888 // Shift Left by variable
8889 instruct salI_rReg_CL(rRegI dst, rcx_RegI shift, rFlagsReg cr)
8890 %{
8891   match(Set dst (LShiftI dst shift));
8892   effect(KILL cr);
8893 
8894   format %{ "sall    $dst, $shift" %}
8895   opcode(0xD3, 0x4); /* D3 /4 */
8896   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
8897   ins_pipe(ialu_reg_reg);
8898 %}
8899 
8900 // Shift Left by variable
8901 instruct salI_mem_CL(memory dst, rcx_RegI shift, rFlagsReg cr)
8902 %{
8903   match(Set dst (StoreI dst (LShiftI (LoadI dst) shift)));
8904   effect(KILL cr);
8905 
8906   format %{ "sall    $dst, $shift" %}
8907   opcode(0xD3, 0x4); /* D3 /4 */
8908   ins_encode(REX_mem(dst), OpcP, RM_opc_mem(secondary, dst));
8909   ins_pipe(ialu_mem_reg);
8910 %}
8911 
8912 // Arithmetic shift right by one
8913 instruct sarI_rReg_1(rRegI dst, immI1 shift, rFlagsReg cr)
8914 %{
8915   match(Set dst (RShiftI dst shift));
8916   effect(KILL cr);
8917 
8918   format %{ "sarl    $dst, $shift" %}
8919   opcode(0xD1, 0x7); /* D1 /7 */
8920   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
8921   ins_pipe(ialu_reg);
8922 %}
8923 
8924 // Arithmetic shift right by one
8925 instruct sarI_mem_1(memory dst, immI1 shift, rFlagsReg cr)
8926 %{
8927   match(Set dst (StoreI dst (RShiftI (LoadI dst) shift)));
8928   effect(KILL cr);
8929 
8930   format %{ "sarl    $dst, $shift" %}
8931   opcode(0xD1, 0x7); /* D1 /7 */
8932   ins_encode(REX_mem(dst), OpcP, RM_opc_mem(secondary, dst));
8933   ins_pipe(ialu_mem_imm);
8934 %}
8935 
8936 // Arithmetic Shift Right by 8-bit immediate
8937 instruct sarI_rReg_imm(rRegI dst, immI8 shift, rFlagsReg cr)
8938 %{
8939   match(Set dst (RShiftI dst shift));
8940   effect(KILL cr);
8941 
8942   format %{ "sarl    $dst, $shift" %}
8943   opcode(0xC1, 0x7); /* C1 /7 ib */
8944   ins_encode(reg_opc_imm(dst, shift));
8945   ins_pipe(ialu_mem_imm);
8946 %}
8947 
8948 // Arithmetic Shift Right by 8-bit immediate
8949 instruct sarI_mem_imm(memory dst, immI8 shift, rFlagsReg cr)
8950 %{
8951   match(Set dst (StoreI dst (RShiftI (LoadI dst) shift)));
8952   effect(KILL cr);
8953 
8954   format %{ "sarl    $dst, $shift" %}
8955   opcode(0xC1, 0x7); /* C1 /7 ib */
8956   ins_encode(REX_mem(dst), OpcP, RM_opc_mem(secondary, dst), Con8or32(shift));
8957   ins_pipe(ialu_mem_imm);
8958 %}
8959 
8960 // Arithmetic Shift Right by variable
8961 instruct sarI_rReg_CL(rRegI dst, rcx_RegI shift, rFlagsReg cr)
8962 %{
8963   match(Set dst (RShiftI dst shift));
8964   effect(KILL cr);
8965 
8966   format %{ "sarl    $dst, $shift" %}
8967   opcode(0xD3, 0x7); /* D3 /7 */
8968   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
8969   ins_pipe(ialu_reg_reg);
8970 %}
8971 
8972 // Arithmetic Shift Right by variable
8973 instruct sarI_mem_CL(memory dst, rcx_RegI shift, rFlagsReg cr)
8974 %{
8975   match(Set dst (StoreI dst (RShiftI (LoadI dst) shift)));
8976   effect(KILL cr);
8977 
8978   format %{ "sarl    $dst, $shift" %}
8979   opcode(0xD3, 0x7); /* D3 /7 */
8980   ins_encode(REX_mem(dst), OpcP, RM_opc_mem(secondary, dst));
8981   ins_pipe(ialu_mem_reg);
8982 %}
8983 
8984 // Logical shift right by one
8985 instruct shrI_rReg_1(rRegI dst, immI1 shift, rFlagsReg cr)
8986 %{
8987   match(Set dst (URShiftI dst shift));
8988   effect(KILL cr);
8989 
8990   format %{ "shrl    $dst, $shift" %}
8991   opcode(0xD1, 0x5); /* D1 /5 */
8992   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
8993   ins_pipe(ialu_reg);
8994 %}
8995 
8996 // Logical shift right by one
8997 instruct shrI_mem_1(memory dst, immI1 shift, rFlagsReg cr)
8998 %{
8999   match(Set dst (StoreI dst (URShiftI (LoadI dst) shift)));
9000   effect(KILL cr);
9001 
9002   format %{ "shrl    $dst, $shift" %}
9003   opcode(0xD1, 0x5); /* D1 /5 */
9004   ins_encode(REX_mem(dst), OpcP, RM_opc_mem(secondary, dst));
9005   ins_pipe(ialu_mem_imm);
9006 %}
9007 
9008 // Logical Shift Right by 8-bit immediate
9009 instruct shrI_rReg_imm(rRegI dst, immI8 shift, rFlagsReg cr)
9010 %{
9011   match(Set dst (URShiftI dst shift));
9012   effect(KILL cr);
9013 
9014   format %{ "shrl    $dst, $shift" %}
9015   opcode(0xC1, 0x5); /* C1 /5 ib */
9016   ins_encode(reg_opc_imm(dst, shift));
9017   ins_pipe(ialu_reg);
9018 %}
9019 
9020 // Logical Shift Right by 8-bit immediate
9021 instruct shrI_mem_imm(memory dst, immI8 shift, rFlagsReg cr)
9022 %{
9023   match(Set dst (StoreI dst (URShiftI (LoadI dst) shift)));
9024   effect(KILL cr);
9025 
9026   format %{ "shrl    $dst, $shift" %}
9027   opcode(0xC1, 0x5); /* C1 /5 ib */
9028   ins_encode(REX_mem(dst), OpcP, RM_opc_mem(secondary, dst), Con8or32(shift));
9029   ins_pipe(ialu_mem_imm);
9030 %}
9031 
9032 // Logical Shift Right by variable
9033 instruct shrI_rReg_CL(rRegI dst, rcx_RegI shift, rFlagsReg cr)
9034 %{
9035   match(Set dst (URShiftI dst shift));
9036   effect(KILL cr);
9037 
9038   format %{ "shrl    $dst, $shift" %}
9039   opcode(0xD3, 0x5); /* D3 /5 */
9040   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
9041   ins_pipe(ialu_reg_reg);
9042 %}
9043 
9044 // Logical Shift Right by variable
9045 instruct shrI_mem_CL(memory dst, rcx_RegI shift, rFlagsReg cr)
9046 %{
9047   match(Set dst (StoreI dst (URShiftI (LoadI dst) shift)));
9048   effect(KILL cr);
9049 
9050   format %{ "shrl    $dst, $shift" %}
9051   opcode(0xD3, 0x5); /* D3 /5 */
9052   ins_encode(REX_mem(dst), OpcP, RM_opc_mem(secondary, dst));
9053   ins_pipe(ialu_mem_reg);
9054 %}
9055 
9056 // Long Shift Instructions
9057 // Shift Left by one
9058 instruct salL_rReg_1(rRegL dst, immI1 shift, rFlagsReg cr)
9059 %{
9060   match(Set dst (LShiftL dst shift));
9061   effect(KILL cr);
9062 
9063   format %{ "salq    $dst, $shift" %}
9064   opcode(0xD1, 0x4); /* D1 /4 */
9065   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst));
9066   ins_pipe(ialu_reg);
9067 %}
9068 
9069 // Shift Left by one
9070 instruct salL_mem_1(memory dst, immI1 shift, rFlagsReg cr)
9071 %{
9072   match(Set dst (StoreL dst (LShiftL (LoadL dst) shift)));
9073   effect(KILL cr);
9074 
9075   format %{ "salq    $dst, $shift" %}
9076   opcode(0xD1, 0x4); /* D1 /4 */
9077   ins_encode(REX_mem_wide(dst), OpcP, RM_opc_mem(secondary, dst));
9078   ins_pipe(ialu_mem_imm);
9079 %}
9080 
9081 // Shift Left by 8-bit immediate
9082 instruct salL_rReg_imm(rRegL dst, immI8 shift, rFlagsReg cr)
9083 %{
9084   match(Set dst (LShiftL dst shift));
9085   effect(KILL cr);
9086 
9087   format %{ "salq    $dst, $shift" %}
9088   opcode(0xC1, 0x4); /* C1 /4 ib */
9089   ins_encode(reg_opc_imm_wide(dst, shift));
9090   ins_pipe(ialu_reg);
9091 %}
9092 
9093 // Shift Left by 8-bit immediate
9094 instruct salL_mem_imm(memory dst, immI8 shift, rFlagsReg cr)
9095 %{
9096   match(Set dst (StoreL dst (LShiftL (LoadL dst) shift)));
9097   effect(KILL cr);
9098 
9099   format %{ "salq    $dst, $shift" %}
9100   opcode(0xC1, 0x4); /* C1 /4 ib */
9101   ins_encode(REX_mem_wide(dst), OpcP,
9102              RM_opc_mem(secondary, dst), Con8or32(shift));
9103   ins_pipe(ialu_mem_imm);
9104 %}
9105 
9106 // Shift Left by variable
9107 instruct salL_rReg_CL(rRegL dst, rcx_RegI shift, rFlagsReg cr)
9108 %{
9109   match(Set dst (LShiftL dst shift));
9110   effect(KILL cr);
9111 
9112   format %{ "salq    $dst, $shift" %}
9113   opcode(0xD3, 0x4); /* D3 /4 */
9114   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst));
9115   ins_pipe(ialu_reg_reg);
9116 %}
9117 
9118 // Shift Left by variable
9119 instruct salL_mem_CL(memory dst, rcx_RegI shift, rFlagsReg cr)
9120 %{
9121   match(Set dst (StoreL dst (LShiftL (LoadL dst) shift)));
9122   effect(KILL cr);
9123 
9124   format %{ "salq    $dst, $shift" %}
9125   opcode(0xD3, 0x4); /* D3 /4 */
9126   ins_encode(REX_mem_wide(dst), OpcP, RM_opc_mem(secondary, dst));
9127   ins_pipe(ialu_mem_reg);
9128 %}
9129 
9130 // Arithmetic shift right by one
9131 instruct sarL_rReg_1(rRegL dst, immI1 shift, rFlagsReg cr)
9132 %{
9133   match(Set dst (RShiftL dst shift));
9134   effect(KILL cr);
9135 
9136   format %{ "sarq    $dst, $shift" %}
9137   opcode(0xD1, 0x7); /* D1 /7 */
9138   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst));
9139   ins_pipe(ialu_reg);
9140 %}
9141 
9142 // Arithmetic shift right by one
9143 instruct sarL_mem_1(memory dst, immI1 shift, rFlagsReg cr)
9144 %{
9145   match(Set dst (StoreL dst (RShiftL (LoadL dst) shift)));
9146   effect(KILL cr);
9147 
9148   format %{ "sarq    $dst, $shift" %}
9149   opcode(0xD1, 0x7); /* D1 /7 */
9150   ins_encode(REX_mem_wide(dst), OpcP, RM_opc_mem(secondary, dst));
9151   ins_pipe(ialu_mem_imm);
9152 %}
9153 
9154 // Arithmetic Shift Right by 8-bit immediate
9155 instruct sarL_rReg_imm(rRegL dst, immI8 shift, rFlagsReg cr)
9156 %{
9157   match(Set dst (RShiftL dst shift));
9158   effect(KILL cr);
9159 
9160   format %{ "sarq    $dst, $shift" %}
9161   opcode(0xC1, 0x7); /* C1 /7 ib */
9162   ins_encode(reg_opc_imm_wide(dst, shift));
9163   ins_pipe(ialu_mem_imm);
9164 %}
9165 
9166 // Arithmetic Shift Right by 8-bit immediate
9167 instruct sarL_mem_imm(memory dst, immI8 shift, rFlagsReg cr)
9168 %{
9169   match(Set dst (StoreL dst (RShiftL (LoadL dst) shift)));
9170   effect(KILL cr);
9171 
9172   format %{ "sarq    $dst, $shift" %}
9173   opcode(0xC1, 0x7); /* C1 /7 ib */
9174   ins_encode(REX_mem_wide(dst), OpcP,
9175              RM_opc_mem(secondary, dst), Con8or32(shift));
9176   ins_pipe(ialu_mem_imm);
9177 %}
9178 
9179 // Arithmetic Shift Right by variable
9180 instruct sarL_rReg_CL(rRegL dst, rcx_RegI shift, rFlagsReg cr)
9181 %{
9182   match(Set dst (RShiftL dst shift));
9183   effect(KILL cr);
9184 
9185   format %{ "sarq    $dst, $shift" %}
9186   opcode(0xD3, 0x7); /* D3 /7 */
9187   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst));
9188   ins_pipe(ialu_reg_reg);
9189 %}
9190 
9191 // Arithmetic Shift Right by variable
9192 instruct sarL_mem_CL(memory dst, rcx_RegI shift, rFlagsReg cr)
9193 %{
9194   match(Set dst (StoreL dst (RShiftL (LoadL dst) shift)));
9195   effect(KILL cr);
9196 
9197   format %{ "sarq    $dst, $shift" %}
9198   opcode(0xD3, 0x7); /* D3 /7 */
9199   ins_encode(REX_mem_wide(dst), OpcP, RM_opc_mem(secondary, dst));
9200   ins_pipe(ialu_mem_reg);
9201 %}
9202 
9203 // Logical shift right by one
9204 instruct shrL_rReg_1(rRegL dst, immI1 shift, rFlagsReg cr)
9205 %{
9206   match(Set dst (URShiftL dst shift));
9207   effect(KILL cr);
9208 
9209   format %{ "shrq    $dst, $shift" %}
9210   opcode(0xD1, 0x5); /* D1 /5 */
9211   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst ));
9212   ins_pipe(ialu_reg);
9213 %}
9214 
9215 // Logical shift right by one
9216 instruct shrL_mem_1(memory dst, immI1 shift, rFlagsReg cr)
9217 %{
9218   match(Set dst (StoreL dst (URShiftL (LoadL dst) shift)));
9219   effect(KILL cr);
9220 
9221   format %{ "shrq    $dst, $shift" %}
9222   opcode(0xD1, 0x5); /* D1 /5 */
9223   ins_encode(REX_mem_wide(dst), OpcP, RM_opc_mem(secondary, dst));
9224   ins_pipe(ialu_mem_imm);
9225 %}
9226 
9227 // Logical Shift Right by 8-bit immediate
9228 instruct shrL_rReg_imm(rRegL dst, immI8 shift, rFlagsReg cr)
9229 %{
9230   match(Set dst (URShiftL dst shift));
9231   effect(KILL cr);
9232 
9233   format %{ "shrq    $dst, $shift" %}
9234   opcode(0xC1, 0x5); /* C1 /5 ib */
9235   ins_encode(reg_opc_imm_wide(dst, shift));
9236   ins_pipe(ialu_reg);
9237 %}
9238 
9239 
9240 // Logical Shift Right by 8-bit immediate
9241 instruct shrL_mem_imm(memory dst, immI8 shift, rFlagsReg cr)
9242 %{
9243   match(Set dst (StoreL dst (URShiftL (LoadL dst) shift)));
9244   effect(KILL cr);
9245 
9246   format %{ "shrq    $dst, $shift" %}
9247   opcode(0xC1, 0x5); /* C1 /5 ib */
9248   ins_encode(REX_mem_wide(dst), OpcP,
9249              RM_opc_mem(secondary, dst), Con8or32(shift));
9250   ins_pipe(ialu_mem_imm);
9251 %}
9252 
9253 // Logical Shift Right by variable
9254 instruct shrL_rReg_CL(rRegL dst, rcx_RegI shift, rFlagsReg cr)
9255 %{
9256   match(Set dst (URShiftL dst shift));
9257   effect(KILL cr);
9258 
9259   format %{ "shrq    $dst, $shift" %}
9260   opcode(0xD3, 0x5); /* D3 /5 */
9261   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst));
9262   ins_pipe(ialu_reg_reg);
9263 %}
9264 
9265 // Logical Shift Right by variable
9266 instruct shrL_mem_CL(memory dst, rcx_RegI shift, rFlagsReg cr)
9267 %{
9268   match(Set dst (StoreL dst (URShiftL (LoadL dst) shift)));
9269   effect(KILL cr);
9270 
9271   format %{ "shrq    $dst, $shift" %}
9272   opcode(0xD3, 0x5); /* D3 /5 */
9273   ins_encode(REX_mem_wide(dst), OpcP, RM_opc_mem(secondary, dst));
9274   ins_pipe(ialu_mem_reg);
9275 %}
9276 
9277 // Logical Shift Right by 24, followed by Arithmetic Shift Left by 24.
9278 // This idiom is used by the compiler for the i2b bytecode.
9279 instruct i2b(rRegI dst, rRegI src, immI_24 twentyfour)
9280 %{
9281   match(Set dst (RShiftI (LShiftI src twentyfour) twentyfour));
9282 
9283   format %{ "movsbl  $dst, $src\t# i2b" %}
9284   opcode(0x0F, 0xBE);
9285   ins_encode(REX_reg_breg(dst, src), OpcP, OpcS, reg_reg(dst, src));
9286   ins_pipe(ialu_reg_reg);
9287 %}
9288 
9289 // Logical Shift Right by 16, followed by Arithmetic Shift Left by 16.
9290 // This idiom is used by the compiler the i2s bytecode.
9291 instruct i2s(rRegI dst, rRegI src, immI_16 sixteen)
9292 %{
9293   match(Set dst (RShiftI (LShiftI src sixteen) sixteen));
9294 
9295   format %{ "movswl  $dst, $src\t# i2s" %}
9296   opcode(0x0F, 0xBF);
9297   ins_encode(REX_reg_reg(dst, src), OpcP, OpcS, reg_reg(dst, src));
9298   ins_pipe(ialu_reg_reg);
9299 %}
9300 
9301 // ROL/ROR instructions
9302 
9303 // ROL expand
9304 instruct rolI_rReg_imm1(rRegI dst, rFlagsReg cr) %{
9305   effect(KILL cr, USE_DEF dst);
9306 
9307   format %{ "roll    $dst" %}
9308   opcode(0xD1, 0x0); /* Opcode  D1 /0 */
9309   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
9310   ins_pipe(ialu_reg);
9311 %}
9312 
9313 instruct rolI_rReg_imm8(rRegI dst, immI8 shift, rFlagsReg cr) %{
9314   effect(USE_DEF dst, USE shift, KILL cr);
9315 
9316   format %{ "roll    $dst, $shift" %}
9317   opcode(0xC1, 0x0); /* Opcode C1 /0 ib */
9318   ins_encode( reg_opc_imm(dst, shift) );
9319   ins_pipe(ialu_reg);
9320 %}
9321 
9322 instruct rolI_rReg_CL(no_rcx_RegI dst, rcx_RegI shift, rFlagsReg cr)
9323 %{
9324   effect(USE_DEF dst, USE shift, KILL cr);
9325 
9326   format %{ "roll    $dst, $shift" %}
9327   opcode(0xD3, 0x0); /* Opcode D3 /0 */
9328   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
9329   ins_pipe(ialu_reg_reg);
9330 %}
9331 // end of ROL expand
9332 
9333 // Rotate Left by one
9334 instruct rolI_rReg_i1(rRegI dst, immI1 lshift, immI_M1 rshift, rFlagsReg cr)
9335 %{
9336   match(Set dst (OrI (LShiftI dst lshift) (URShiftI dst rshift)));
9337 
9338   expand %{
9339     rolI_rReg_imm1(dst, cr);
9340   %}
9341 %}
9342 
9343 // Rotate Left by 8-bit immediate
9344 instruct rolI_rReg_i8(rRegI dst, immI8 lshift, immI8 rshift, rFlagsReg cr)
9345 %{
9346   predicate(0 == ((n->in(1)->in(2)->get_int() + n->in(2)->in(2)->get_int()) & 0x1f));
9347   match(Set dst (OrI (LShiftI dst lshift) (URShiftI dst rshift)));
9348 
9349   expand %{
9350     rolI_rReg_imm8(dst, lshift, cr);
9351   %}
9352 %}
9353 
9354 // Rotate Left by variable
9355 instruct rolI_rReg_Var_C0(no_rcx_RegI dst, rcx_RegI shift, immI0 zero, rFlagsReg cr)
9356 %{
9357   match(Set dst (OrI (LShiftI dst shift) (URShiftI dst (SubI zero shift))));
9358 
9359   expand %{
9360     rolI_rReg_CL(dst, shift, cr);
9361   %}
9362 %}
9363 
9364 // Rotate Left by variable
9365 instruct rolI_rReg_Var_C32(no_rcx_RegI dst, rcx_RegI shift, immI_32 c32, rFlagsReg cr)
9366 %{
9367   match(Set dst (OrI (LShiftI dst shift) (URShiftI dst (SubI c32 shift))));
9368 
9369   expand %{
9370     rolI_rReg_CL(dst, shift, cr);
9371   %}
9372 %}
9373 
9374 // ROR expand
9375 instruct rorI_rReg_imm1(rRegI dst, rFlagsReg cr)
9376 %{
9377   effect(USE_DEF dst, KILL cr);
9378 
9379   format %{ "rorl    $dst" %}
9380   opcode(0xD1, 0x1); /* D1 /1 */
9381   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
9382   ins_pipe(ialu_reg);
9383 %}
9384 
9385 instruct rorI_rReg_imm8(rRegI dst, immI8 shift, rFlagsReg cr)
9386 %{
9387   effect(USE_DEF dst, USE shift, KILL cr);
9388 
9389   format %{ "rorl    $dst, $shift" %}
9390   opcode(0xC1, 0x1); /* C1 /1 ib */
9391   ins_encode(reg_opc_imm(dst, shift));
9392   ins_pipe(ialu_reg);
9393 %}
9394 
9395 instruct rorI_rReg_CL(no_rcx_RegI dst, rcx_RegI shift, rFlagsReg cr)
9396 %{
9397   effect(USE_DEF dst, USE shift, KILL cr);
9398 
9399   format %{ "rorl    $dst, $shift" %}
9400   opcode(0xD3, 0x1); /* D3 /1 */
9401   ins_encode(REX_reg(dst), OpcP, reg_opc(dst));
9402   ins_pipe(ialu_reg_reg);
9403 %}
9404 // end of ROR expand
9405 
9406 // Rotate Right by one
9407 instruct rorI_rReg_i1(rRegI dst, immI1 rshift, immI_M1 lshift, rFlagsReg cr)
9408 %{
9409   match(Set dst (OrI (URShiftI dst rshift) (LShiftI dst lshift)));
9410 
9411   expand %{
9412     rorI_rReg_imm1(dst, cr);
9413   %}
9414 %}
9415 
9416 // Rotate Right by 8-bit immediate
9417 instruct rorI_rReg_i8(rRegI dst, immI8 rshift, immI8 lshift, rFlagsReg cr)
9418 %{
9419   predicate(0 == ((n->in(1)->in(2)->get_int() + n->in(2)->in(2)->get_int()) & 0x1f));
9420   match(Set dst (OrI (URShiftI dst rshift) (LShiftI dst lshift)));
9421 
9422   expand %{
9423     rorI_rReg_imm8(dst, rshift, cr);
9424   %}
9425 %}
9426 
9427 // Rotate Right by variable
9428 instruct rorI_rReg_Var_C0(no_rcx_RegI dst, rcx_RegI shift, immI0 zero, rFlagsReg cr)
9429 %{
9430   match(Set dst (OrI (URShiftI dst shift) (LShiftI dst (SubI zero shift))));
9431 
9432   expand %{
9433     rorI_rReg_CL(dst, shift, cr);
9434   %}
9435 %}
9436 
9437 // Rotate Right by variable
9438 instruct rorI_rReg_Var_C32(no_rcx_RegI dst, rcx_RegI shift, immI_32 c32, rFlagsReg cr)
9439 %{
9440   match(Set dst (OrI (URShiftI dst shift) (LShiftI dst (SubI c32 shift))));
9441 
9442   expand %{
9443     rorI_rReg_CL(dst, shift, cr);
9444   %}
9445 %}
9446 
9447 // for long rotate
9448 // ROL expand
9449 instruct rolL_rReg_imm1(rRegL dst, rFlagsReg cr) %{
9450   effect(USE_DEF dst, KILL cr);
9451 
9452   format %{ "rolq    $dst" %}
9453   opcode(0xD1, 0x0); /* Opcode  D1 /0 */
9454   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst));
9455   ins_pipe(ialu_reg);
9456 %}
9457 
9458 instruct rolL_rReg_imm8(rRegL dst, immI8 shift, rFlagsReg cr) %{
9459   effect(USE_DEF dst, USE shift, KILL cr);
9460 
9461   format %{ "rolq    $dst, $shift" %}
9462   opcode(0xC1, 0x0); /* Opcode C1 /0 ib */
9463   ins_encode( reg_opc_imm_wide(dst, shift) );
9464   ins_pipe(ialu_reg);
9465 %}
9466 
9467 instruct rolL_rReg_CL(no_rcx_RegL dst, rcx_RegI shift, rFlagsReg cr)
9468 %{
9469   effect(USE_DEF dst, USE shift, KILL cr);
9470 
9471   format %{ "rolq    $dst, $shift" %}
9472   opcode(0xD3, 0x0); /* Opcode D3 /0 */
9473   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst));
9474   ins_pipe(ialu_reg_reg);
9475 %}
9476 // end of ROL expand
9477 
9478 // Rotate Left by one
9479 instruct rolL_rReg_i1(rRegL dst, immI1 lshift, immI_M1 rshift, rFlagsReg cr)
9480 %{
9481   match(Set dst (OrL (LShiftL dst lshift) (URShiftL dst rshift)));
9482 
9483   expand %{
9484     rolL_rReg_imm1(dst, cr);
9485   %}
9486 %}
9487 
9488 // Rotate Left by 8-bit immediate
9489 instruct rolL_rReg_i8(rRegL dst, immI8 lshift, immI8 rshift, rFlagsReg cr)
9490 %{
9491   predicate(0 == ((n->in(1)->in(2)->get_int() + n->in(2)->in(2)->get_int()) & 0x3f));
9492   match(Set dst (OrL (LShiftL dst lshift) (URShiftL dst rshift)));
9493 
9494   expand %{
9495     rolL_rReg_imm8(dst, lshift, cr);
9496   %}
9497 %}
9498 
9499 // Rotate Left by variable
9500 instruct rolL_rReg_Var_C0(no_rcx_RegL dst, rcx_RegI shift, immI0 zero, rFlagsReg cr)
9501 %{
9502   match(Set dst (OrL (LShiftL dst shift) (URShiftL dst (SubI zero shift))));
9503 
9504   expand %{
9505     rolL_rReg_CL(dst, shift, cr);
9506   %}
9507 %}
9508 
9509 // Rotate Left by variable
9510 instruct rolL_rReg_Var_C64(no_rcx_RegL dst, rcx_RegI shift, immI_64 c64, rFlagsReg cr)
9511 %{
9512   match(Set dst (OrL (LShiftL dst shift) (URShiftL dst (SubI c64 shift))));
9513 
9514   expand %{
9515     rolL_rReg_CL(dst, shift, cr);
9516   %}
9517 %}
9518 
9519 // ROR expand
9520 instruct rorL_rReg_imm1(rRegL dst, rFlagsReg cr)
9521 %{
9522   effect(USE_DEF dst, KILL cr);
9523 
9524   format %{ "rorq    $dst" %}
9525   opcode(0xD1, 0x1); /* D1 /1 */
9526   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst));
9527   ins_pipe(ialu_reg);
9528 %}
9529 
9530 instruct rorL_rReg_imm8(rRegL dst, immI8 shift, rFlagsReg cr)
9531 %{
9532   effect(USE_DEF dst, USE shift, KILL cr);
9533 
9534   format %{ "rorq    $dst, $shift" %}
9535   opcode(0xC1, 0x1); /* C1 /1 ib */
9536   ins_encode(reg_opc_imm_wide(dst, shift));
9537   ins_pipe(ialu_reg);
9538 %}
9539 
9540 instruct rorL_rReg_CL(no_rcx_RegL dst, rcx_RegI shift, rFlagsReg cr)
9541 %{
9542   effect(USE_DEF dst, USE shift, KILL cr);
9543 
9544   format %{ "rorq    $dst, $shift" %}
9545   opcode(0xD3, 0x1); /* D3 /1 */
9546   ins_encode(REX_reg_wide(dst), OpcP, reg_opc(dst));
9547   ins_pipe(ialu_reg_reg);
9548 %}
9549 // end of ROR expand
9550 
9551 // Rotate Right by one
9552 instruct rorL_rReg_i1(rRegL dst, immI1 rshift, immI_M1 lshift, rFlagsReg cr)
9553 %{
9554   match(Set dst (OrL (URShiftL dst rshift) (LShiftL dst lshift)));
9555 
9556   expand %{
9557     rorL_rReg_imm1(dst, cr);
9558   %}
9559 %}
9560 
9561 // Rotate Right by 8-bit immediate
9562 instruct rorL_rReg_i8(rRegL dst, immI8 rshift, immI8 lshift, rFlagsReg cr)
9563 %{
9564   predicate(0 == ((n->in(1)->in(2)->get_int() + n->in(2)->in(2)->get_int()) & 0x3f));
9565   match(Set dst (OrL (URShiftL dst rshift) (LShiftL dst lshift)));
9566 
9567   expand %{
9568     rorL_rReg_imm8(dst, rshift, cr);
9569   %}
9570 %}
9571 
9572 // Rotate Right by variable
9573 instruct rorL_rReg_Var_C0(no_rcx_RegL dst, rcx_RegI shift, immI0 zero, rFlagsReg cr)
9574 %{
9575   match(Set dst (OrL (URShiftL dst shift) (LShiftL dst (SubI zero shift))));
9576 
9577   expand %{
9578     rorL_rReg_CL(dst, shift, cr);
9579   %}
9580 %}
9581 
9582 // Rotate Right by variable
9583 instruct rorL_rReg_Var_C64(no_rcx_RegL dst, rcx_RegI shift, immI_64 c64, rFlagsReg cr)
9584 %{
9585   match(Set dst (OrL (URShiftL dst shift) (LShiftL dst (SubI c64 shift))));
9586 
9587   expand %{
9588     rorL_rReg_CL(dst, shift, cr);
9589   %}
9590 %}
9591 
9592 // Logical Instructions
9593 
9594 // Integer Logical Instructions
9595 
9596 // And Instructions
9597 // And Register with Register
9598 instruct andI_rReg(rRegI dst, rRegI src, rFlagsReg cr)
9599 %{
9600   match(Set dst (AndI dst src));
9601   effect(KILL cr);
9602 
9603   format %{ "andl    $dst, $src\t# int" %}
9604   opcode(0x23);
9605   ins_encode(REX_reg_reg(dst, src), OpcP, reg_reg(dst, src));
9606   ins_pipe(ialu_reg_reg);
9607 %}
9608 
9609 // And Register with Immediate 255
9610 instruct andI_rReg_imm255(rRegI dst, immI_255 src)
9611 %{
9612   match(Set dst (AndI dst src));
9613 
9614   format %{ "movzbl  $dst, $dst\t# int & 0xFF" %}
9615   opcode(0x0F, 0xB6);
9616   ins_encode(REX_reg_breg(dst, dst), OpcP, OpcS, reg_reg(dst, dst));
9617   ins_pipe(ialu_reg);
9618 %}
9619 
9620 // And Register with Immediate 255 and promote to long
9621 instruct andI2L_rReg_imm255(rRegL dst, rRegI src, immI_255 mask)
9622 %{
9623   match(Set dst (ConvI2L (AndI src mask)));
9624 
9625   format %{ "movzbl  $dst, $src\t# int & 0xFF -> long" %}
9626   opcode(0x0F, 0xB6);
9627   ins_encode(REX_reg_breg(dst, src), OpcP, OpcS, reg_reg(dst, src));
9628   ins_pipe(ialu_reg);
9629 %}
9630 
9631 // And Register with Immediate 65535
9632 instruct andI_rReg_imm65535(rRegI dst, immI_65535 src)
9633 %{
9634   match(Set dst (AndI dst src));
9635 
9636   format %{ "movzwl  $dst, $dst\t# int & 0xFFFF" %}
9637   opcode(0x0F, 0xB7);
9638   ins_encode(REX_reg_reg(dst, dst), OpcP, OpcS, reg_reg(dst, dst));
9639   ins_pipe(ialu_reg);
9640 %}
9641 
9642 // And Register with Immediate 65535 and promote to long
9643 instruct andI2L_rReg_imm65535(rRegL dst, rRegI src, immI_65535 mask)
9644 %{
9645   match(Set dst (ConvI2L (AndI src mask)));
9646 
9647   format %{ "movzwl  $dst, $src\t# int & 0xFFFF -> long" %}
9648   opcode(0x0F, 0xB7);
9649   ins_encode(REX_reg_reg(dst, src), OpcP, OpcS, reg_reg(dst, src));
9650   ins_pipe(ialu_reg);
9651 %}
9652 
9653 // And Register with Immediate
9654 instruct andI_rReg_imm(rRegI dst, immI src, rFlagsReg cr)
9655 %{
9656   match(Set dst (AndI dst src));
9657   effect(KILL cr);
9658 
9659   format %{ "andl    $dst, $src\t# int" %}
9660   opcode(0x81, 0x04); /* Opcode 81 /4 */
9661   ins_encode(OpcSErm(dst, src), Con8or32(src));
9662   ins_pipe(ialu_reg);
9663 %}
9664 
9665 // And Register with Memory
9666 instruct andI_rReg_mem(rRegI dst, memory src, rFlagsReg cr)
9667 %{
9668   match(Set dst (AndI dst (LoadI src)));
9669   effect(KILL cr);
9670 
9671   ins_cost(125);
9672   format %{ "andl    $dst, $src\t# int" %}
9673   opcode(0x23);
9674   ins_encode(REX_reg_mem(dst, src), OpcP, reg_mem(dst, src));
9675   ins_pipe(ialu_reg_mem);
9676 %}
9677 
9678 // And Memory with Register
9679 instruct andI_mem_rReg(memory dst, rRegI src, rFlagsReg cr)
9680 %{
9681   match(Set dst (StoreI dst (AndI (LoadI dst) src)));
9682   effect(KILL cr);
9683 
9684   ins_cost(150);
9685   format %{ "andl    $dst, $src\t# int" %}
9686   opcode(0x21); /* Opcode 21 /r */
9687   ins_encode(REX_reg_mem(src, dst), OpcP, reg_mem(src, dst));
9688   ins_pipe(ialu_mem_reg);
9689 %}
9690 
9691 // And Memory with Immediate
9692 instruct andI_mem_imm(memory dst, immI src, rFlagsReg cr)
9693 %{
9694   match(Set dst (StoreI dst (AndI (LoadI dst) src)));
9695   effect(KILL cr);
9696 
9697   ins_cost(125);
9698   format %{ "andl    $dst, $src\t# int" %}
9699   opcode(0x81, 0x4); /* Opcode 81 /4 id */
9700   ins_encode(REX_mem(dst), OpcSE(src),
9701              RM_opc_mem(secondary, dst), Con8or32(src));
9702   ins_pipe(ialu_mem_imm);
9703 %}
9704 
9705 // Or Instructions
9706 // Or Register with Register
9707 instruct orI_rReg(rRegI dst, rRegI src, rFlagsReg cr)
9708 %{
9709   match(Set dst (OrI dst src));
9710   effect(KILL cr);
9711 
9712   format %{ "orl     $dst, $src\t# int" %}
9713   opcode(0x0B);
9714   ins_encode(REX_reg_reg(dst, src), OpcP, reg_reg(dst, src));
9715   ins_pipe(ialu_reg_reg);
9716 %}
9717 
9718 // Or Register with Immediate
9719 instruct orI_rReg_imm(rRegI dst, immI src, rFlagsReg cr)
9720 %{
9721   match(Set dst (OrI dst src));
9722   effect(KILL cr);
9723 
9724   format %{ "orl     $dst, $src\t# int" %}
9725   opcode(0x81, 0x01); /* Opcode 81 /1 id */
9726   ins_encode(OpcSErm(dst, src), Con8or32(src));
9727   ins_pipe(ialu_reg);
9728 %}
9729 
9730 // Or Register with Memory
9731 instruct orI_rReg_mem(rRegI dst, memory src, rFlagsReg cr)
9732 %{
9733   match(Set dst (OrI dst (LoadI src)));
9734   effect(KILL cr);
9735 
9736   ins_cost(125);
9737   format %{ "orl     $dst, $src\t# int" %}
9738   opcode(0x0B);
9739   ins_encode(REX_reg_mem(dst, src), OpcP, reg_mem(dst, src));
9740   ins_pipe(ialu_reg_mem);
9741 %}
9742 
9743 // Or Memory with Register
9744 instruct orI_mem_rReg(memory dst, rRegI src, rFlagsReg cr)
9745 %{
9746   match(Set dst (StoreI dst (OrI (LoadI dst) src)));
9747   effect(KILL cr);
9748 
9749   ins_cost(150);
9750   format %{ "orl     $dst, $src\t# int" %}
9751   opcode(0x09); /* Opcode 09 /r */
9752   ins_encode(REX_reg_mem(src, dst), OpcP, reg_mem(src, dst));
9753   ins_pipe(ialu_mem_reg);
9754 %}
9755 
9756 // Or Memory with Immediate
9757 instruct orI_mem_imm(memory dst, immI src, rFlagsReg cr)
9758 %{
9759   match(Set dst (StoreI dst (OrI (LoadI dst) src)));
9760   effect(KILL cr);
9761 
9762   ins_cost(125);
9763   format %{ "orl     $dst, $src\t# int" %}
9764   opcode(0x81, 0x1); /* Opcode 81 /1 id */
9765   ins_encode(REX_mem(dst), OpcSE(src),
9766              RM_opc_mem(secondary, dst), Con8or32(src));
9767   ins_pipe(ialu_mem_imm);
9768 %}
9769 
9770 // Xor Instructions
9771 // Xor Register with Register
9772 instruct xorI_rReg(rRegI dst, rRegI src, rFlagsReg cr)
9773 %{
9774   match(Set dst (XorI dst src));
9775   effect(KILL cr);
9776 
9777   format %{ "xorl    $dst, $src\t# int" %}
9778   opcode(0x33);
9779   ins_encode(REX_reg_reg(dst, src), OpcP, reg_reg(dst, src));
9780   ins_pipe(ialu_reg_reg);
9781 %}
9782 
9783 // Xor Register with Immediate -1
9784 instruct xorI_rReg_im1(rRegI dst, immI_M1 imm) %{
9785   match(Set dst (XorI dst imm));
9786 
9787   format %{ "not    $dst" %}
9788   ins_encode %{
9789      __ notl($dst$$Register);
9790   %}
9791   ins_pipe(ialu_reg);
9792 %}
9793 
9794 // Xor Register with Immediate
9795 instruct xorI_rReg_imm(rRegI dst, immI src, rFlagsReg cr)
9796 %{
9797   match(Set dst (XorI dst src));
9798   effect(KILL cr);
9799 
9800   format %{ "xorl    $dst, $src\t# int" %}
9801   opcode(0x81, 0x06); /* Opcode 81 /6 id */
9802   ins_encode(OpcSErm(dst, src), Con8or32(src));
9803   ins_pipe(ialu_reg);
9804 %}
9805 
9806 // Xor Register with Memory
9807 instruct xorI_rReg_mem(rRegI dst, memory src, rFlagsReg cr)
9808 %{
9809   match(Set dst (XorI dst (LoadI src)));
9810   effect(KILL cr);
9811 
9812   ins_cost(125);
9813   format %{ "xorl    $dst, $src\t# int" %}
9814   opcode(0x33);
9815   ins_encode(REX_reg_mem(dst, src), OpcP, reg_mem(dst, src));
9816   ins_pipe(ialu_reg_mem);
9817 %}
9818 
9819 // Xor Memory with Register
9820 instruct xorI_mem_rReg(memory dst, rRegI src, rFlagsReg cr)
9821 %{
9822   match(Set dst (StoreI dst (XorI (LoadI dst) src)));
9823   effect(KILL cr);
9824 
9825   ins_cost(150);
9826   format %{ "xorl    $dst, $src\t# int" %}
9827   opcode(0x31); /* Opcode 31 /r */
9828   ins_encode(REX_reg_mem(src, dst), OpcP, reg_mem(src, dst));
9829   ins_pipe(ialu_mem_reg);
9830 %}
9831 
9832 // Xor Memory with Immediate
9833 instruct xorI_mem_imm(memory dst, immI src, rFlagsReg cr)
9834 %{
9835   match(Set dst (StoreI dst (XorI (LoadI dst) src)));
9836   effect(KILL cr);
9837 
9838   ins_cost(125);
9839   format %{ "xorl    $dst, $src\t# int" %}
9840   opcode(0x81, 0x6); /* Opcode 81 /6 id */
9841   ins_encode(REX_mem(dst), OpcSE(src),
9842              RM_opc_mem(secondary, dst), Con8or32(src));
9843   ins_pipe(ialu_mem_imm);
9844 %}
9845 
9846 
9847 // Long Logical Instructions
9848 
9849 // And Instructions
9850 // And Register with Register
9851 instruct andL_rReg(rRegL dst, rRegL src, rFlagsReg cr)
9852 %{
9853   match(Set dst (AndL dst src));
9854   effect(KILL cr);
9855 
9856   format %{ "andq    $dst, $src\t# long" %}
9857   opcode(0x23);
9858   ins_encode(REX_reg_reg_wide(dst, src), OpcP, reg_reg(dst, src));
9859   ins_pipe(ialu_reg_reg);
9860 %}
9861 
9862 // And Register with Immediate 255
9863 instruct andL_rReg_imm255(rRegL dst, immL_255 src)
9864 %{
9865   match(Set dst (AndL dst src));
9866 
9867   format %{ "movzbq  $dst, $dst\t# long & 0xFF" %}
9868   opcode(0x0F, 0xB6);
9869   ins_encode(REX_reg_reg_wide(dst, dst), OpcP, OpcS, reg_reg(dst, dst));
9870   ins_pipe(ialu_reg);
9871 %}
9872 
9873 // And Register with Immediate 65535
9874 instruct andL_rReg_imm65535(rRegL dst, immL_65535 src)
9875 %{
9876   match(Set dst (AndL dst src));
9877 
9878   format %{ "movzwq  $dst, $dst\t# long & 0xFFFF" %}
9879   opcode(0x0F, 0xB7);
9880   ins_encode(REX_reg_reg_wide(dst, dst), OpcP, OpcS, reg_reg(dst, dst));
9881   ins_pipe(ialu_reg);
9882 %}
9883 
9884 // And Register with Immediate
9885 instruct andL_rReg_imm(rRegL dst, immL32 src, rFlagsReg cr)
9886 %{
9887   match(Set dst (AndL dst src));
9888   effect(KILL cr);
9889 
9890   format %{ "andq    $dst, $src\t# long" %}
9891   opcode(0x81, 0x04); /* Opcode 81 /4 */
9892   ins_encode(OpcSErm_wide(dst, src), Con8or32(src));
9893   ins_pipe(ialu_reg);
9894 %}
9895 
9896 // And Register with Memory
9897 instruct andL_rReg_mem(rRegL dst, memory src, rFlagsReg cr)
9898 %{
9899   match(Set dst (AndL dst (LoadL src)));
9900   effect(KILL cr);
9901 
9902   ins_cost(125);
9903   format %{ "andq    $dst, $src\t# long" %}
9904   opcode(0x23);
9905   ins_encode(REX_reg_mem_wide(dst, src), OpcP, reg_mem(dst, src));
9906   ins_pipe(ialu_reg_mem);
9907 %}
9908 
9909 // And Memory with Register
9910 instruct andL_mem_rReg(memory dst, rRegL src, rFlagsReg cr)
9911 %{
9912   match(Set dst (StoreL dst (AndL (LoadL dst) src)));
9913   effect(KILL cr);
9914 
9915   ins_cost(150);
9916   format %{ "andq    $dst, $src\t# long" %}
9917   opcode(0x21); /* Opcode 21 /r */
9918   ins_encode(REX_reg_mem_wide(src, dst), OpcP, reg_mem(src, dst));
9919   ins_pipe(ialu_mem_reg);
9920 %}
9921 
9922 // And Memory with Immediate
9923 instruct andL_mem_imm(memory dst, immL32 src, rFlagsReg cr)
9924 %{
9925   match(Set dst (StoreL dst (AndL (LoadL dst) src)));
9926   effect(KILL cr);
9927 
9928   ins_cost(125);
9929   format %{ "andq    $dst, $src\t# long" %}
9930   opcode(0x81, 0x4); /* Opcode 81 /4 id */
9931   ins_encode(REX_mem_wide(dst), OpcSE(src),
9932              RM_opc_mem(secondary, dst), Con8or32(src));
9933   ins_pipe(ialu_mem_imm);
9934 %}
9935 
9936 // Or Instructions
9937 // Or Register with Register
9938 instruct orL_rReg(rRegL dst, rRegL src, rFlagsReg cr)
9939 %{
9940   match(Set dst (OrL dst src));
9941   effect(KILL cr);
9942 
9943   format %{ "orq     $dst, $src\t# long" %}
9944   opcode(0x0B);
9945   ins_encode(REX_reg_reg_wide(dst, src), OpcP, reg_reg(dst, src));
9946   ins_pipe(ialu_reg_reg);
9947 %}
9948 
9949 // Use any_RegP to match R15 (TLS register) without spilling.
9950 instruct orL_rReg_castP2X(rRegL dst, any_RegP src, rFlagsReg cr) %{
9951   match(Set dst (OrL dst (CastP2X src)));
9952   effect(KILL cr);
9953 
9954   format %{ "orq     $dst, $src\t# long" %}
9955   opcode(0x0B);
9956   ins_encode(REX_reg_reg_wide(dst, src), OpcP, reg_reg(dst, src));
9957   ins_pipe(ialu_reg_reg);
9958 %}
9959 
9960 
9961 // Or Register with Immediate
9962 instruct orL_rReg_imm(rRegL dst, immL32 src, rFlagsReg cr)
9963 %{
9964   match(Set dst (OrL dst src));
9965   effect(KILL cr);
9966 
9967   format %{ "orq     $dst, $src\t# long" %}
9968   opcode(0x81, 0x01); /* Opcode 81 /1 id */
9969   ins_encode(OpcSErm_wide(dst, src), Con8or32(src));
9970   ins_pipe(ialu_reg);
9971 %}
9972 
9973 // Or Register with Memory
9974 instruct orL_rReg_mem(rRegL dst, memory src, rFlagsReg cr)
9975 %{
9976   match(Set dst (OrL dst (LoadL src)));
9977   effect(KILL cr);
9978 
9979   ins_cost(125);
9980   format %{ "orq     $dst, $src\t# long" %}
9981   opcode(0x0B);
9982   ins_encode(REX_reg_mem_wide(dst, src), OpcP, reg_mem(dst, src));
9983   ins_pipe(ialu_reg_mem);
9984 %}
9985 
9986 // Or Memory with Register
9987 instruct orL_mem_rReg(memory dst, rRegL src, rFlagsReg cr)
9988 %{
9989   match(Set dst (StoreL dst (OrL (LoadL dst) src)));
9990   effect(KILL cr);
9991 
9992   ins_cost(150);
9993   format %{ "orq     $dst, $src\t# long" %}
9994   opcode(0x09); /* Opcode 09 /r */
9995   ins_encode(REX_reg_mem_wide(src, dst), OpcP, reg_mem(src, dst));
9996   ins_pipe(ialu_mem_reg);
9997 %}
9998 
9999 // Or Memory with Immediate
10000 instruct orL_mem_imm(memory dst, immL32 src, rFlagsReg cr)
10001 %{
10002   match(Set dst (StoreL dst (OrL (LoadL dst) src)));
10003   effect(KILL cr);
10004 
10005   ins_cost(125);
10006   format %{ "orq     $dst, $src\t# long" %}
10007   opcode(0x81, 0x1); /* Opcode 81 /1 id */
10008   ins_encode(REX_mem_wide(dst), OpcSE(src),
10009              RM_opc_mem(secondary, dst), Con8or32(src));
10010   ins_pipe(ialu_mem_imm);
10011 %}
10012 
10013 // Xor Instructions
10014 // Xor Register with Register
10015 instruct xorL_rReg(rRegL dst, rRegL src, rFlagsReg cr)
10016 %{
10017   match(Set dst (XorL dst src));
10018   effect(KILL cr);
10019 
10020   format %{ "xorq    $dst, $src\t# long" %}
10021   opcode(0x33);
10022   ins_encode(REX_reg_reg_wide(dst, src), OpcP, reg_reg(dst, src));
10023   ins_pipe(ialu_reg_reg);
10024 %}
10025 
10026 // Xor Register with Immediate -1
10027 instruct xorL_rReg_im1(rRegL dst, immL_M1 imm) %{
10028   match(Set dst (XorL dst imm));
10029 
10030   format %{ "notq   $dst" %}
10031   ins_encode %{
10032      __ notq($dst$$Register);
10033   %}
10034   ins_pipe(ialu_reg);
10035 %}
10036 
10037 // Xor Register with Immediate
10038 instruct xorL_rReg_imm(rRegL dst, immL32 src, rFlagsReg cr)
10039 %{
10040   match(Set dst (XorL dst src));
10041   effect(KILL cr);
10042 
10043   format %{ "xorq    $dst, $src\t# long" %}
10044   opcode(0x81, 0x06); /* Opcode 81 /6 id */
10045   ins_encode(OpcSErm_wide(dst, src), Con8or32(src));
10046   ins_pipe(ialu_reg);
10047 %}
10048 
10049 // Xor Register with Memory
10050 instruct xorL_rReg_mem(rRegL dst, memory src, rFlagsReg cr)
10051 %{
10052   match(Set dst (XorL dst (LoadL src)));
10053   effect(KILL cr);
10054 
10055   ins_cost(125);
10056   format %{ "xorq    $dst, $src\t# long" %}
10057   opcode(0x33);
10058   ins_encode(REX_reg_mem_wide(dst, src), OpcP, reg_mem(dst, src));
10059   ins_pipe(ialu_reg_mem);
10060 %}
10061 
10062 // Xor Memory with Register
10063 instruct xorL_mem_rReg(memory dst, rRegL src, rFlagsReg cr)
10064 %{
10065   match(Set dst (StoreL dst (XorL (LoadL dst) src)));
10066   effect(KILL cr);
10067 
10068   ins_cost(150);
10069   format %{ "xorq    $dst, $src\t# long" %}
10070   opcode(0x31); /* Opcode 31 /r */
10071   ins_encode(REX_reg_mem_wide(src, dst), OpcP, reg_mem(src, dst));
10072   ins_pipe(ialu_mem_reg);
10073 %}
10074 
10075 // Xor Memory with Immediate
10076 instruct xorL_mem_imm(memory dst, immL32 src, rFlagsReg cr)
10077 %{
10078   match(Set dst (StoreL dst (XorL (LoadL dst) src)));
10079   effect(KILL cr);
10080 
10081   ins_cost(125);
10082   format %{ "xorq    $dst, $src\t# long" %}
10083   opcode(0x81, 0x6); /* Opcode 81 /6 id */
10084   ins_encode(REX_mem_wide(dst), OpcSE(src),
10085              RM_opc_mem(secondary, dst), Con8or32(src));
10086   ins_pipe(ialu_mem_imm);
10087 %}
10088 
10089 // Convert Int to Boolean
10090 instruct convI2B(rRegI dst, rRegI src, rFlagsReg cr)
10091 %{
10092   match(Set dst (Conv2B src));
10093   effect(KILL cr);
10094 
10095   format %{ "testl   $src, $src\t# ci2b\n\t"
10096             "setnz   $dst\n\t"
10097             "movzbl  $dst, $dst" %}
10098   ins_encode(REX_reg_reg(src, src), opc_reg_reg(0x85, src, src), // testl
10099              setNZ_reg(dst),
10100              REX_reg_breg(dst, dst), // movzbl
10101              Opcode(0x0F), Opcode(0xB6), reg_reg(dst, dst));
10102   ins_pipe(pipe_slow); // XXX
10103 %}
10104 
10105 // Convert Pointer to Boolean
10106 instruct convP2B(rRegI dst, rRegP src, rFlagsReg cr)
10107 %{
10108   match(Set dst (Conv2B src));
10109   effect(KILL cr);
10110 
10111   format %{ "testq   $src, $src\t# cp2b\n\t"
10112             "setnz   $dst\n\t"
10113             "movzbl  $dst, $dst" %}
10114   ins_encode(REX_reg_reg_wide(src, src), opc_reg_reg(0x85, src, src), // testq
10115              setNZ_reg(dst),
10116              REX_reg_breg(dst, dst), // movzbl
10117              Opcode(0x0F), Opcode(0xB6), reg_reg(dst, dst));
10118   ins_pipe(pipe_slow); // XXX
10119 %}
10120 
10121 instruct cmpLTMask(rRegI dst, rRegI p, rRegI q, rFlagsReg cr)
10122 %{
10123   match(Set dst (CmpLTMask p q));
10124   effect(KILL cr);
10125 
10126   ins_cost(400); // XXX
10127   format %{ "cmpl    $p, $q\t# cmpLTMask\n\t"
10128             "setlt   $dst\n\t"
10129             "movzbl  $dst, $dst\n\t"
10130             "negl    $dst" %}
10131   ins_encode(REX_reg_reg(p, q), opc_reg_reg(0x3B, p, q), // cmpl
10132              setLT_reg(dst),
10133              REX_reg_breg(dst, dst), // movzbl
10134              Opcode(0x0F), Opcode(0xB6), reg_reg(dst, dst),
10135              neg_reg(dst));
10136   ins_pipe(pipe_slow);
10137 %}
10138 
10139 instruct cmpLTMask0(rRegI dst, immI0 zero, rFlagsReg cr)
10140 %{
10141   match(Set dst (CmpLTMask dst zero));
10142   effect(KILL cr);
10143 
10144   ins_cost(100); // XXX
10145   format %{ "sarl    $dst, #31\t# cmpLTMask0" %}
10146   opcode(0xC1, 0x7);  /* C1 /7 ib */
10147   ins_encode(reg_opc_imm(dst, 0x1F));
10148   ins_pipe(ialu_reg);
10149 %}
10150 
10151 
10152 instruct cadd_cmpLTMask(rRegI p, rRegI q, rRegI y, rRegI tmp, rFlagsReg cr)
10153 %{
10154   match(Set p (AddI (AndI (CmpLTMask p q) y) (SubI p q)));
10155   effect(TEMP tmp, KILL cr);
10156 
10157   ins_cost(400); // XXX
10158   format %{ "subl    $p, $q\t# cadd_cmpLTMask1\n\t"
10159             "sbbl    $tmp, $tmp\n\t"
10160             "andl    $tmp, $y\n\t"
10161             "addl    $p, $tmp" %}
10162   ins_encode %{
10163     Register Rp = $p$$Register;
10164     Register Rq = $q$$Register;
10165     Register Ry = $y$$Register;
10166     Register Rt = $tmp$$Register;
10167     __ subl(Rp, Rq);
10168     __ sbbl(Rt, Rt);
10169     __ andl(Rt, Ry);
10170     __ addl(Rp, Rt);
10171   %}
10172   ins_pipe(pipe_cmplt);
10173 %}
10174 
10175 //---------- FP Instructions------------------------------------------------
10176 
10177 instruct cmpF_cc_reg(rFlagsRegU cr, regF src1, regF src2)
10178 %{
10179   match(Set cr (CmpF src1 src2));
10180 
10181   ins_cost(145);
10182   format %{ "ucomiss $src1, $src2\n\t"
10183             "jnp,s   exit\n\t"
10184             "pushfq\t# saw NaN, set CF\n\t"
10185             "andq    [rsp], #0xffffff2b\n\t"
10186             "popfq\n"
10187     "exit:   nop\t# avoid branch to branch" %}
10188   opcode(0x0F, 0x2E);
10189   ins_encode(REX_reg_reg(src1, src2), OpcP, OpcS, reg_reg(src1, src2),
10190              cmpfp_fixup);
10191   ins_pipe(pipe_slow);
10192 %}
10193 
10194 instruct cmpF_cc_reg_CF(rFlagsRegUCF cr, regF src1, regF src2) %{
10195   match(Set cr (CmpF src1 src2));
10196 
10197   ins_cost(145);
10198   format %{ "ucomiss $src1, $src2" %}
10199   ins_encode %{
10200     __ ucomiss($src1$$XMMRegister, $src2$$XMMRegister);
10201   %}
10202   ins_pipe(pipe_slow);
10203 %}
10204 
10205 instruct cmpF_cc_mem(rFlagsRegU cr, regF src1, memory src2)
10206 %{
10207   match(Set cr (CmpF src1 (LoadF src2)));
10208 
10209   ins_cost(145);
10210   format %{ "ucomiss $src1, $src2\n\t"
10211             "jnp,s   exit\n\t"
10212             "pushfq\t# saw NaN, set CF\n\t"
10213             "andq    [rsp], #0xffffff2b\n\t"
10214             "popfq\n"
10215     "exit:   nop\t# avoid branch to branch" %}
10216   opcode(0x0F, 0x2E);
10217   ins_encode(REX_reg_mem(src1, src2), OpcP, OpcS, reg_mem(src1, src2),
10218              cmpfp_fixup);
10219   ins_pipe(pipe_slow);
10220 %}
10221 
10222 instruct cmpF_cc_memCF(rFlagsRegUCF cr, regF src1, memory src2) %{
10223   match(Set cr (CmpF src1 (LoadF src2)));
10224 
10225   ins_cost(100);
10226   format %{ "ucomiss $src1, $src2" %}
10227   opcode(0x0F, 0x2E);
10228   ins_encode(REX_reg_mem(src1, src2), OpcP, OpcS, reg_mem(src1, src2));
10229   ins_pipe(pipe_slow);
10230 %}
10231 
10232 instruct cmpF_cc_imm(rFlagsRegU cr, regF src, immF con) %{
10233   match(Set cr (CmpF src con));
10234 
10235   ins_cost(145);
10236   format %{ "ucomiss $src, [$constantaddress]\t# load from constant table: float=$con\n\t"
10237             "jnp,s   exit\n\t"
10238             "pushfq\t# saw NaN, set CF\n\t"
10239             "andq    [rsp], #0xffffff2b\n\t"
10240             "popfq\n"
10241     "exit:   nop\t# avoid branch to branch" %}
10242   ins_encode %{
10243     __ ucomiss($src$$XMMRegister, $constantaddress($con));
10244     emit_cmpfp_fixup(_masm);
10245   %}
10246   ins_pipe(pipe_slow);
10247 %}
10248 
10249 instruct cmpF_cc_immCF(rFlagsRegUCF cr, regF src, immF con) %{
10250   match(Set cr (CmpF src con));
10251   ins_cost(100);
10252   format %{ "ucomiss $src, [$constantaddress]\t# load from constant table: float=$con" %}
10253   ins_encode %{
10254     __ ucomiss($src$$XMMRegister, $constantaddress($con));
10255   %}
10256   ins_pipe(pipe_slow);
10257 %}
10258 
10259 instruct cmpD_cc_reg(rFlagsRegU cr, regD src1, regD src2)
10260 %{
10261   match(Set cr (CmpD src1 src2));
10262 
10263   ins_cost(145);
10264   format %{ "ucomisd $src1, $src2\n\t"
10265             "jnp,s   exit\n\t"
10266             "pushfq\t# saw NaN, set CF\n\t"
10267             "andq    [rsp], #0xffffff2b\n\t"
10268             "popfq\n"
10269     "exit:   nop\t# avoid branch to branch" %}
10270   opcode(0x66, 0x0F, 0x2E);
10271   ins_encode(OpcP, REX_reg_reg(src1, src2), OpcS, OpcT, reg_reg(src1, src2),
10272              cmpfp_fixup);
10273   ins_pipe(pipe_slow);
10274 %}
10275 
10276 instruct cmpD_cc_reg_CF(rFlagsRegUCF cr, regD src1, regD src2) %{
10277   match(Set cr (CmpD src1 src2));
10278 
10279   ins_cost(100);
10280   format %{ "ucomisd $src1, $src2 test" %}
10281   ins_encode %{
10282     __ ucomisd($src1$$XMMRegister, $src2$$XMMRegister);
10283   %}
10284   ins_pipe(pipe_slow);
10285 %}
10286 
10287 instruct cmpD_cc_mem(rFlagsRegU cr, regD src1, memory src2)
10288 %{
10289   match(Set cr (CmpD src1 (LoadD src2)));
10290 
10291   ins_cost(145);
10292   format %{ "ucomisd $src1, $src2\n\t"
10293             "jnp,s   exit\n\t"
10294             "pushfq\t# saw NaN, set CF\n\t"
10295             "andq    [rsp], #0xffffff2b\n\t"
10296             "popfq\n"
10297     "exit:   nop\t# avoid branch to branch" %}
10298   opcode(0x66, 0x0F, 0x2E);
10299   ins_encode(OpcP, REX_reg_mem(src1, src2), OpcS, OpcT, reg_mem(src1, src2),
10300              cmpfp_fixup);
10301   ins_pipe(pipe_slow);
10302 %}
10303 
10304 instruct cmpD_cc_memCF(rFlagsRegUCF cr, regD src1, memory src2) %{
10305   match(Set cr (CmpD src1 (LoadD src2)));
10306 
10307   ins_cost(100);
10308   format %{ "ucomisd $src1, $src2" %}
10309   opcode(0x66, 0x0F, 0x2E);
10310   ins_encode(OpcP, REX_reg_mem(src1, src2), OpcS, OpcT, reg_mem(src1, src2));
10311   ins_pipe(pipe_slow);
10312 %}
10313 
10314 instruct cmpD_cc_imm(rFlagsRegU cr, regD src, immD con) %{
10315   match(Set cr (CmpD src con));
10316 
10317   ins_cost(145);
10318   format %{ "ucomisd $src, [$constantaddress]\t# load from constant table: double=$con\n\t"
10319             "jnp,s   exit\n\t"
10320             "pushfq\t# saw NaN, set CF\n\t"
10321             "andq    [rsp], #0xffffff2b\n\t"
10322             "popfq\n"
10323     "exit:   nop\t# avoid branch to branch" %}
10324   ins_encode %{
10325     __ ucomisd($src$$XMMRegister, $constantaddress($con));
10326     emit_cmpfp_fixup(_masm);
10327   %}
10328   ins_pipe(pipe_slow);
10329 %}
10330 
10331 instruct cmpD_cc_immCF(rFlagsRegUCF cr, regD src, immD con) %{
10332   match(Set cr (CmpD src con));
10333   ins_cost(100);
10334   format %{ "ucomisd $src, [$constantaddress]\t# load from constant table: double=$con" %}
10335   ins_encode %{
10336     __ ucomisd($src$$XMMRegister, $constantaddress($con));
10337   %}
10338   ins_pipe(pipe_slow);
10339 %}
10340 
10341 // Compare into -1,0,1
10342 instruct cmpF_reg(rRegI dst, regF src1, regF src2, rFlagsReg cr)
10343 %{
10344   match(Set dst (CmpF3 src1 src2));
10345   effect(KILL cr);
10346 
10347   ins_cost(275);
10348   format %{ "ucomiss $src1, $src2\n\t"
10349             "movl    $dst, #-1\n\t"
10350             "jp,s    done\n\t"
10351             "jb,s    done\n\t"
10352             "setne   $dst\n\t"
10353             "movzbl  $dst, $dst\n"
10354     "done:" %}
10355 
10356   opcode(0x0F, 0x2E);
10357   ins_encode(REX_reg_reg(src1, src2), OpcP, OpcS, reg_reg(src1, src2),
10358              cmpfp3(dst));
10359   ins_pipe(pipe_slow);
10360 %}
10361 
10362 // Compare into -1,0,1
10363 instruct cmpF_mem(rRegI dst, regF src1, memory src2, rFlagsReg cr)
10364 %{
10365   match(Set dst (CmpF3 src1 (LoadF src2)));
10366   effect(KILL cr);
10367 
10368   ins_cost(275);
10369   format %{ "ucomiss $src1, $src2\n\t"
10370             "movl    $dst, #-1\n\t"
10371             "jp,s    done\n\t"
10372             "jb,s    done\n\t"
10373             "setne   $dst\n\t"
10374             "movzbl  $dst, $dst\n"
10375     "done:" %}
10376 
10377   opcode(0x0F, 0x2E);
10378   ins_encode(REX_reg_mem(src1, src2), OpcP, OpcS, reg_mem(src1, src2),
10379              cmpfp3(dst));
10380   ins_pipe(pipe_slow);
10381 %}
10382 
10383 // Compare into -1,0,1
10384 instruct cmpF_imm(rRegI dst, regF src, immF con, rFlagsReg cr) %{
10385   match(Set dst (CmpF3 src con));
10386   effect(KILL cr);
10387 
10388   ins_cost(275);
10389   format %{ "ucomiss $src, [$constantaddress]\t# load from constant table: float=$con\n\t"
10390             "movl    $dst, #-1\n\t"
10391             "jp,s    done\n\t"
10392             "jb,s    done\n\t"
10393             "setne   $dst\n\t"
10394             "movzbl  $dst, $dst\n"
10395     "done:" %}
10396   ins_encode %{
10397     Label L_done;
10398     Register Rdst = $dst$$Register;
10399     __ ucomiss($src$$XMMRegister, $constantaddress($con));
10400     __ movl(Rdst, -1);
10401     __ jcc(Assembler::parity, L_done);
10402     __ jcc(Assembler::below, L_done);
10403     __ setb(Assembler::notEqual, Rdst);
10404     __ movzbl(Rdst, Rdst);
10405     __ bind(L_done);
10406   %}
10407   ins_pipe(pipe_slow);
10408 %}
10409 
10410 // Compare into -1,0,1
10411 instruct cmpD_reg(rRegI dst, regD src1, regD src2, rFlagsReg cr)
10412 %{
10413   match(Set dst (CmpD3 src1 src2));
10414   effect(KILL cr);
10415 
10416   ins_cost(275);
10417   format %{ "ucomisd $src1, $src2\n\t"
10418             "movl    $dst, #-1\n\t"
10419             "jp,s    done\n\t"
10420             "jb,s    done\n\t"
10421             "setne   $dst\n\t"
10422             "movzbl  $dst, $dst\n"
10423     "done:" %}
10424 
10425   opcode(0x66, 0x0F, 0x2E);
10426   ins_encode(OpcP, REX_reg_reg(src1, src2), OpcS, OpcT, reg_reg(src1, src2),
10427              cmpfp3(dst));
10428   ins_pipe(pipe_slow);
10429 %}
10430 
10431 // Compare into -1,0,1
10432 instruct cmpD_mem(rRegI dst, regD src1, memory src2, rFlagsReg cr)
10433 %{
10434   match(Set dst (CmpD3 src1 (LoadD src2)));
10435   effect(KILL cr);
10436 
10437   ins_cost(275);
10438   format %{ "ucomisd $src1, $src2\n\t"
10439             "movl    $dst, #-1\n\t"
10440             "jp,s    done\n\t"
10441             "jb,s    done\n\t"
10442             "setne   $dst\n\t"
10443             "movzbl  $dst, $dst\n"
10444     "done:" %}
10445 
10446   opcode(0x66, 0x0F, 0x2E);
10447   ins_encode(OpcP, REX_reg_mem(src1, src2), OpcS, OpcT, reg_mem(src1, src2),
10448              cmpfp3(dst));
10449   ins_pipe(pipe_slow);
10450 %}
10451 
10452 // Compare into -1,0,1
10453 instruct cmpD_imm(rRegI dst, regD src, immD con, rFlagsReg cr) %{
10454   match(Set dst (CmpD3 src con));
10455   effect(KILL cr);
10456 
10457   ins_cost(275);
10458   format %{ "ucomisd $src, [$constantaddress]\t# load from constant table: double=$con\n\t"
10459             "movl    $dst, #-1\n\t"
10460             "jp,s    done\n\t"
10461             "jb,s    done\n\t"
10462             "setne   $dst\n\t"
10463             "movzbl  $dst, $dst\n"
10464     "done:" %}
10465   ins_encode %{
10466     Register Rdst = $dst$$Register;
10467     Label L_done;
10468     __ ucomisd($src$$XMMRegister, $constantaddress($con));
10469     __ movl(Rdst, -1);
10470     __ jcc(Assembler::parity, L_done);
10471     __ jcc(Assembler::below, L_done);
10472     __ setb(Assembler::notEqual, Rdst);
10473     __ movzbl(Rdst, Rdst);
10474     __ bind(L_done);
10475   %}
10476   ins_pipe(pipe_slow);
10477 %}
10478 
10479 instruct addF_reg(regF dst, regF src)
10480 %{
10481   match(Set dst (AddF dst src));
10482 
10483   format %{ "addss   $dst, $src" %}
10484   ins_cost(150); // XXX
10485   opcode(0xF3, 0x0F, 0x58);
10486   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
10487   ins_pipe(pipe_slow);
10488 %}
10489 
10490 instruct addF_mem(regF dst, memory src)
10491 %{
10492   match(Set dst (AddF dst (LoadF src)));
10493 
10494   format %{ "addss   $dst, $src" %}
10495   ins_cost(150); // XXX
10496   opcode(0xF3, 0x0F, 0x58);
10497   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
10498   ins_pipe(pipe_slow);
10499 %}
10500 
10501 instruct addF_imm(regF dst, immF con) %{
10502   match(Set dst (AddF dst con));
10503   format %{ "addss   $dst, [$constantaddress]\t# load from constant table: float=$con" %}
10504   ins_cost(150); // XXX
10505   ins_encode %{
10506     __ addss($dst$$XMMRegister, $constantaddress($con));
10507   %}
10508   ins_pipe(pipe_slow);
10509 %}
10510 
10511 instruct addD_reg(regD dst, regD src)
10512 %{
10513   match(Set dst (AddD dst src));
10514 
10515   format %{ "addsd   $dst, $src" %}
10516   ins_cost(150); // XXX
10517   opcode(0xF2, 0x0F, 0x58);
10518   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
10519   ins_pipe(pipe_slow);
10520 %}
10521 
10522 instruct addD_mem(regD dst, memory src)
10523 %{
10524   match(Set dst (AddD dst (LoadD src)));
10525 
10526   format %{ "addsd   $dst, $src" %}
10527   ins_cost(150); // XXX
10528   opcode(0xF2, 0x0F, 0x58);
10529   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
10530   ins_pipe(pipe_slow);
10531 %}
10532 
10533 instruct addD_imm(regD dst, immD con) %{
10534   match(Set dst (AddD dst con));
10535   format %{ "addsd   $dst, [$constantaddress]\t# load from constant table: double=$con" %}
10536   ins_cost(150); // XXX
10537   ins_encode %{
10538     __ addsd($dst$$XMMRegister, $constantaddress($con));
10539   %}
10540   ins_pipe(pipe_slow);
10541 %}
10542 
10543 instruct subF_reg(regF dst, regF src)
10544 %{
10545   match(Set dst (SubF dst src));
10546 
10547   format %{ "subss   $dst, $src" %}
10548   ins_cost(150); // XXX
10549   opcode(0xF3, 0x0F, 0x5C);
10550   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
10551   ins_pipe(pipe_slow);
10552 %}
10553 
10554 instruct subF_mem(regF dst, memory src)
10555 %{
10556   match(Set dst (SubF dst (LoadF src)));
10557 
10558   format %{ "subss   $dst, $src" %}
10559   ins_cost(150); // XXX
10560   opcode(0xF3, 0x0F, 0x5C);
10561   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
10562   ins_pipe(pipe_slow);
10563 %}
10564 
10565 instruct subF_imm(regF dst, immF con) %{
10566   match(Set dst (SubF dst con));
10567   format %{ "subss   $dst, [$constantaddress]\t# load from constant table: float=$con" %}
10568   ins_cost(150); // XXX
10569   ins_encode %{
10570     __ subss($dst$$XMMRegister, $constantaddress($con));
10571   %}
10572   ins_pipe(pipe_slow);
10573 %}
10574 
10575 instruct subD_reg(regD dst, regD src)
10576 %{
10577   match(Set dst (SubD dst src));
10578 
10579   format %{ "subsd   $dst, $src" %}
10580   ins_cost(150); // XXX
10581   opcode(0xF2, 0x0F, 0x5C);
10582   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
10583   ins_pipe(pipe_slow);
10584 %}
10585 
10586 instruct subD_mem(regD dst, memory src)
10587 %{
10588   match(Set dst (SubD dst (LoadD src)));
10589 
10590   format %{ "subsd   $dst, $src" %}
10591   ins_cost(150); // XXX
10592   opcode(0xF2, 0x0F, 0x5C);
10593   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
10594   ins_pipe(pipe_slow);
10595 %}
10596 
10597 instruct subD_imm(regD dst, immD con) %{
10598   match(Set dst (SubD dst con));
10599   format %{ "subsd   $dst, [$constantaddress]\t# load from constant table: double=$con" %}
10600   ins_cost(150); // XXX
10601   ins_encode %{
10602     __ subsd($dst$$XMMRegister, $constantaddress($con));
10603   %}
10604   ins_pipe(pipe_slow);
10605 %}
10606 
10607 instruct mulF_reg(regF dst, regF src)
10608 %{
10609   match(Set dst (MulF dst src));
10610 
10611   format %{ "mulss   $dst, $src" %}
10612   ins_cost(150); // XXX
10613   opcode(0xF3, 0x0F, 0x59);
10614   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
10615   ins_pipe(pipe_slow);
10616 %}
10617 
10618 instruct mulF_mem(regF dst, memory src)
10619 %{
10620   match(Set dst (MulF dst (LoadF src)));
10621 
10622   format %{ "mulss   $dst, $src" %}
10623   ins_cost(150); // XXX
10624   opcode(0xF3, 0x0F, 0x59);
10625   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
10626   ins_pipe(pipe_slow);
10627 %}
10628 
10629 instruct mulF_imm(regF dst, immF con) %{
10630   match(Set dst (MulF dst con));
10631   format %{ "mulss   $dst, [$constantaddress]\t# load from constant table: float=$con" %}
10632   ins_cost(150); // XXX
10633   ins_encode %{
10634     __ mulss($dst$$XMMRegister, $constantaddress($con));
10635   %}
10636   ins_pipe(pipe_slow);
10637 %}
10638 
10639 instruct mulD_reg(regD dst, regD src)
10640 %{
10641   match(Set dst (MulD dst src));
10642 
10643   format %{ "mulsd   $dst, $src" %}
10644   ins_cost(150); // XXX
10645   opcode(0xF2, 0x0F, 0x59);
10646   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
10647   ins_pipe(pipe_slow);
10648 %}
10649 
10650 instruct mulD_mem(regD dst, memory src)
10651 %{
10652   match(Set dst (MulD dst (LoadD src)));
10653 
10654   format %{ "mulsd   $dst, $src" %}
10655   ins_cost(150); // XXX
10656   opcode(0xF2, 0x0F, 0x59);
10657   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
10658   ins_pipe(pipe_slow);
10659 %}
10660 
10661 instruct mulD_imm(regD dst, immD con) %{
10662   match(Set dst (MulD dst con));
10663   format %{ "mulsd   $dst, [$constantaddress]\t# load from constant table: double=$con" %}
10664   ins_cost(150); // XXX
10665   ins_encode %{
10666     __ mulsd($dst$$XMMRegister, $constantaddress($con));
10667   %}
10668   ins_pipe(pipe_slow);
10669 %}
10670 
10671 instruct divF_reg(regF dst, regF src)
10672 %{
10673   match(Set dst (DivF dst src));
10674 
10675   format %{ "divss   $dst, $src" %}
10676   ins_cost(150); // XXX
10677   opcode(0xF3, 0x0F, 0x5E);
10678   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
10679   ins_pipe(pipe_slow);
10680 %}
10681 
10682 instruct divF_mem(regF dst, memory src)
10683 %{
10684   match(Set dst (DivF dst (LoadF src)));
10685 
10686   format %{ "divss   $dst, $src" %}
10687   ins_cost(150); // XXX
10688   opcode(0xF3, 0x0F, 0x5E);
10689   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
10690   ins_pipe(pipe_slow);
10691 %}
10692 
10693 instruct divF_imm(regF dst, immF con) %{
10694   match(Set dst (DivF dst con));
10695   format %{ "divss   $dst, [$constantaddress]\t# load from constant table: float=$con" %}
10696   ins_cost(150); // XXX
10697   ins_encode %{
10698     __ divss($dst$$XMMRegister, $constantaddress($con));
10699   %}
10700   ins_pipe(pipe_slow);
10701 %}
10702 
10703 instruct divD_reg(regD dst, regD src)
10704 %{
10705   match(Set dst (DivD dst src));
10706 
10707   format %{ "divsd   $dst, $src" %}
10708   ins_cost(150); // XXX
10709   opcode(0xF2, 0x0F, 0x5E);
10710   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
10711   ins_pipe(pipe_slow);
10712 %}
10713 
10714 instruct divD_mem(regD dst, memory src)
10715 %{
10716   match(Set dst (DivD dst (LoadD src)));
10717 
10718   format %{ "divsd   $dst, $src" %}
10719   ins_cost(150); // XXX
10720   opcode(0xF2, 0x0F, 0x5E);
10721   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
10722   ins_pipe(pipe_slow);
10723 %}
10724 
10725 instruct divD_imm(regD dst, immD con) %{
10726   match(Set dst (DivD dst con));
10727   format %{ "divsd   $dst, [$constantaddress]\t# load from constant table: double=$con" %}
10728   ins_cost(150); // XXX
10729   ins_encode %{
10730     __ divsd($dst$$XMMRegister, $constantaddress($con));
10731   %}
10732   ins_pipe(pipe_slow);
10733 %}
10734 
10735 instruct sqrtF_reg(regF dst, regF src)
10736 %{
10737   match(Set dst (ConvD2F (SqrtD (ConvF2D src))));
10738 
10739   format %{ "sqrtss  $dst, $src" %}
10740   ins_cost(150); // XXX
10741   opcode(0xF3, 0x0F, 0x51);
10742   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
10743   ins_pipe(pipe_slow);
10744 %}
10745 
10746 instruct sqrtF_mem(regF dst, memory src)
10747 %{
10748   match(Set dst (ConvD2F (SqrtD (ConvF2D (LoadF src)))));
10749 
10750   format %{ "sqrtss  $dst, $src" %}
10751   ins_cost(150); // XXX
10752   opcode(0xF3, 0x0F, 0x51);
10753   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
10754   ins_pipe(pipe_slow);
10755 %}
10756 
10757 instruct sqrtF_imm(regF dst, immF con) %{
10758   match(Set dst (ConvD2F (SqrtD (ConvF2D con))));
10759   format %{ "sqrtss  $dst, [$constantaddress]\t# load from constant table: float=$con" %}
10760   ins_cost(150); // XXX
10761   ins_encode %{
10762     __ sqrtss($dst$$XMMRegister, $constantaddress($con));
10763   %}
10764   ins_pipe(pipe_slow);
10765 %}
10766 
10767 instruct sqrtD_reg(regD dst, regD src)
10768 %{
10769   match(Set dst (SqrtD src));
10770 
10771   format %{ "sqrtsd  $dst, $src" %}
10772   ins_cost(150); // XXX
10773   opcode(0xF2, 0x0F, 0x51);
10774   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
10775   ins_pipe(pipe_slow);
10776 %}
10777 
10778 instruct sqrtD_mem(regD dst, memory src)
10779 %{
10780   match(Set dst (SqrtD (LoadD src)));
10781 
10782   format %{ "sqrtsd  $dst, $src" %}
10783   ins_cost(150); // XXX
10784   opcode(0xF2, 0x0F, 0x51);
10785   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
10786   ins_pipe(pipe_slow);
10787 %}
10788 
10789 instruct sqrtD_imm(regD dst, immD con) %{
10790   match(Set dst (SqrtD con));
10791   format %{ "sqrtsd  $dst, [$constantaddress]\t# load from constant table: double=$con" %}
10792   ins_cost(150); // XXX
10793   ins_encode %{
10794     __ sqrtsd($dst$$XMMRegister, $constantaddress($con));
10795   %}
10796   ins_pipe(pipe_slow);
10797 %}
10798 
10799 instruct absF_reg(regF dst)
10800 %{
10801   match(Set dst (AbsF dst));
10802 
10803   format %{ "andps   $dst, [0x7fffffff]\t# abs float by sign masking" %}
10804   ins_encode(absF_encoding(dst));
10805   ins_pipe(pipe_slow);
10806 %}
10807 
10808 instruct absD_reg(regD dst)
10809 %{
10810   match(Set dst (AbsD dst));
10811 
10812   format %{ "andpd   $dst, [0x7fffffffffffffff]\t"
10813             "# abs double by sign masking" %}
10814   ins_encode(absD_encoding(dst));
10815   ins_pipe(pipe_slow);
10816 %}
10817 
10818 instruct negF_reg(regF dst)
10819 %{
10820   match(Set dst (NegF dst));
10821 
10822   format %{ "xorps   $dst, [0x80000000]\t# neg float by sign flipping" %}
10823   ins_encode(negF_encoding(dst));
10824   ins_pipe(pipe_slow);
10825 %}
10826 
10827 instruct negD_reg(regD dst)
10828 %{
10829   match(Set dst (NegD dst));
10830 
10831   format %{ "xorpd   $dst, [0x8000000000000000]\t"
10832             "# neg double by sign flipping" %}
10833   ins_encode(negD_encoding(dst));
10834   ins_pipe(pipe_slow);
10835 %}
10836 
10837 // -----------Trig and Trancendental Instructions------------------------------
10838 instruct cosD_reg(regD dst) %{
10839   match(Set dst (CosD dst));
10840 
10841   format %{ "dcos   $dst\n\t" %}
10842   opcode(0xD9, 0xFF);
10843   ins_encode( Push_SrcXD(dst), OpcP, OpcS, Push_ResultXD(dst) );
10844   ins_pipe( pipe_slow );
10845 %}
10846 
10847 instruct sinD_reg(regD dst) %{
10848   match(Set dst (SinD dst));
10849 
10850   format %{ "dsin   $dst\n\t" %}
10851   opcode(0xD9, 0xFE);
10852   ins_encode( Push_SrcXD(dst), OpcP, OpcS, Push_ResultXD(dst) );
10853   ins_pipe( pipe_slow );
10854 %}
10855 
10856 instruct tanD_reg(regD dst) %{
10857   match(Set dst (TanD dst));
10858 
10859   format %{ "dtan   $dst\n\t" %}
10860   ins_encode( Push_SrcXD(dst),
10861               Opcode(0xD9), Opcode(0xF2),   //fptan
10862               Opcode(0xDD), Opcode(0xD8),   //fstp st
10863               Push_ResultXD(dst) );
10864   ins_pipe( pipe_slow );
10865 %}
10866 
10867 instruct log10D_reg(regD dst) %{
10868   // The source and result Double operands in XMM registers
10869   match(Set dst (Log10D dst));
10870   // fldlg2       ; push log_10(2) on the FPU stack; full 80-bit number
10871   // fyl2x        ; compute log_10(2) * log_2(x)
10872   format %{ "fldlg2\t\t\t#Log10\n\t"
10873             "fyl2x\t\t\t# Q=Log10*Log_2(x)\n\t"
10874          %}
10875    ins_encode(Opcode(0xD9), Opcode(0xEC),   // fldlg2
10876               Push_SrcXD(dst),
10877               Opcode(0xD9), Opcode(0xF1),   // fyl2x
10878               Push_ResultXD(dst));
10879 
10880   ins_pipe( pipe_slow );
10881 %}
10882 
10883 instruct logD_reg(regD dst) %{
10884   // The source and result Double operands in XMM registers
10885   match(Set dst (LogD dst));
10886   // fldln2       ; push log_e(2) on the FPU stack; full 80-bit number
10887   // fyl2x        ; compute log_e(2) * log_2(x)
10888   format %{ "fldln2\t\t\t#Log_e\n\t"
10889             "fyl2x\t\t\t# Q=Log_e*Log_2(x)\n\t"
10890          %}
10891   ins_encode( Opcode(0xD9), Opcode(0xED),   // fldln2
10892               Push_SrcXD(dst),
10893               Opcode(0xD9), Opcode(0xF1),   // fyl2x
10894               Push_ResultXD(dst));
10895   ins_pipe( pipe_slow );
10896 %}
10897 
10898 
10899 
10900 //----------Arithmetic Conversion Instructions---------------------------------
10901 
10902 instruct roundFloat_nop(regF dst)
10903 %{
10904   match(Set dst (RoundFloat dst));
10905 
10906   ins_cost(0);
10907   ins_encode();
10908   ins_pipe(empty);
10909 %}
10910 
10911 instruct roundDouble_nop(regD dst)
10912 %{
10913   match(Set dst (RoundDouble dst));
10914 
10915   ins_cost(0);
10916   ins_encode();
10917   ins_pipe(empty);
10918 %}
10919 
10920 instruct convF2D_reg_reg(regD dst, regF src)
10921 %{
10922   match(Set dst (ConvF2D src));
10923 
10924   format %{ "cvtss2sd $dst, $src" %}
10925   opcode(0xF3, 0x0F, 0x5A);
10926   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
10927   ins_pipe(pipe_slow); // XXX
10928 %}
10929 
10930 instruct convF2D_reg_mem(regD dst, memory src)
10931 %{
10932   match(Set dst (ConvF2D (LoadF src)));
10933 
10934   format %{ "cvtss2sd $dst, $src" %}
10935   opcode(0xF3, 0x0F, 0x5A);
10936   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
10937   ins_pipe(pipe_slow); // XXX
10938 %}
10939 
10940 instruct convD2F_reg_reg(regF dst, regD src)
10941 %{
10942   match(Set dst (ConvD2F src));
10943 
10944   format %{ "cvtsd2ss $dst, $src" %}
10945   opcode(0xF2, 0x0F, 0x5A);
10946   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
10947   ins_pipe(pipe_slow); // XXX
10948 %}
10949 
10950 instruct convD2F_reg_mem(regF dst, memory src)
10951 %{
10952   match(Set dst (ConvD2F (LoadD src)));
10953 
10954   format %{ "cvtsd2ss $dst, $src" %}
10955   opcode(0xF2, 0x0F, 0x5A);
10956   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
10957   ins_pipe(pipe_slow); // XXX
10958 %}
10959 
10960 // XXX do mem variants
10961 instruct convF2I_reg_reg(rRegI dst, regF src, rFlagsReg cr)
10962 %{
10963   match(Set dst (ConvF2I src));
10964   effect(KILL cr);
10965 
10966   format %{ "cvttss2sil $dst, $src\t# f2i\n\t"
10967             "cmpl    $dst, #0x80000000\n\t"
10968             "jne,s   done\n\t"
10969             "subq    rsp, #8\n\t"
10970             "movss   [rsp], $src\n\t"
10971             "call    f2i_fixup\n\t"
10972             "popq    $dst\n"
10973     "done:   "%}
10974   opcode(0xF3, 0x0F, 0x2C);
10975   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src),
10976              f2i_fixup(dst, src));
10977   ins_pipe(pipe_slow);
10978 %}
10979 
10980 instruct convF2L_reg_reg(rRegL dst, regF src, rFlagsReg cr)
10981 %{
10982   match(Set dst (ConvF2L src));
10983   effect(KILL cr);
10984 
10985   format %{ "cvttss2siq $dst, $src\t# f2l\n\t"
10986             "cmpq    $dst, [0x8000000000000000]\n\t"
10987             "jne,s   done\n\t"
10988             "subq    rsp, #8\n\t"
10989             "movss   [rsp], $src\n\t"
10990             "call    f2l_fixup\n\t"
10991             "popq    $dst\n"
10992     "done:   "%}
10993   opcode(0xF3, 0x0F, 0x2C);
10994   ins_encode(OpcP, REX_reg_reg_wide(dst, src), OpcS, OpcT, reg_reg(dst, src),
10995              f2l_fixup(dst, src));
10996   ins_pipe(pipe_slow);
10997 %}
10998 
10999 instruct convD2I_reg_reg(rRegI dst, regD src, rFlagsReg cr)
11000 %{
11001   match(Set dst (ConvD2I src));
11002   effect(KILL cr);
11003 
11004   format %{ "cvttsd2sil $dst, $src\t# d2i\n\t"
11005             "cmpl    $dst, #0x80000000\n\t"
11006             "jne,s   done\n\t"
11007             "subq    rsp, #8\n\t"
11008             "movsd   [rsp], $src\n\t"
11009             "call    d2i_fixup\n\t"
11010             "popq    $dst\n"
11011     "done:   "%}
11012   opcode(0xF2, 0x0F, 0x2C);
11013   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src),
11014              d2i_fixup(dst, src));
11015   ins_pipe(pipe_slow);
11016 %}
11017 
11018 instruct convD2L_reg_reg(rRegL dst, regD src, rFlagsReg cr)
11019 %{
11020   match(Set dst (ConvD2L src));
11021   effect(KILL cr);
11022 
11023   format %{ "cvttsd2siq $dst, $src\t# d2l\n\t"
11024             "cmpq    $dst, [0x8000000000000000]\n\t"
11025             "jne,s   done\n\t"
11026             "subq    rsp, #8\n\t"
11027             "movsd   [rsp], $src\n\t"
11028             "call    d2l_fixup\n\t"
11029             "popq    $dst\n"
11030     "done:   "%}
11031   opcode(0xF2, 0x0F, 0x2C);
11032   ins_encode(OpcP, REX_reg_reg_wide(dst, src), OpcS, OpcT, reg_reg(dst, src),
11033              d2l_fixup(dst, src));
11034   ins_pipe(pipe_slow);
11035 %}
11036 
11037 instruct convI2F_reg_reg(regF dst, rRegI src)
11038 %{
11039   predicate(!UseXmmI2F);
11040   match(Set dst (ConvI2F src));
11041 
11042   format %{ "cvtsi2ssl $dst, $src\t# i2f" %}
11043   opcode(0xF3, 0x0F, 0x2A);
11044   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
11045   ins_pipe(pipe_slow); // XXX
11046 %}
11047 
11048 instruct convI2F_reg_mem(regF dst, memory src)
11049 %{
11050   match(Set dst (ConvI2F (LoadI src)));
11051 
11052   format %{ "cvtsi2ssl $dst, $src\t# i2f" %}
11053   opcode(0xF3, 0x0F, 0x2A);
11054   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
11055   ins_pipe(pipe_slow); // XXX
11056 %}
11057 
11058 instruct convI2D_reg_reg(regD dst, rRegI src)
11059 %{
11060   predicate(!UseXmmI2D);
11061   match(Set dst (ConvI2D src));
11062 
11063   format %{ "cvtsi2sdl $dst, $src\t# i2d" %}
11064   opcode(0xF2, 0x0F, 0x2A);
11065   ins_encode(OpcP, REX_reg_reg(dst, src), OpcS, OpcT, reg_reg(dst, src));
11066   ins_pipe(pipe_slow); // XXX
11067 %}
11068 
11069 instruct convI2D_reg_mem(regD dst, memory src)
11070 %{
11071   match(Set dst (ConvI2D (LoadI src)));
11072 
11073   format %{ "cvtsi2sdl $dst, $src\t# i2d" %}
11074   opcode(0xF2, 0x0F, 0x2A);
11075   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
11076   ins_pipe(pipe_slow); // XXX
11077 %}
11078 
11079 instruct convXI2F_reg(regF dst, rRegI src)
11080 %{
11081   predicate(UseXmmI2F);
11082   match(Set dst (ConvI2F src));
11083 
11084   format %{ "movdl $dst, $src\n\t"
11085             "cvtdq2psl $dst, $dst\t# i2f" %}
11086   ins_encode %{
11087     __ movdl($dst$$XMMRegister, $src$$Register);
11088     __ cvtdq2ps($dst$$XMMRegister, $dst$$XMMRegister);
11089   %}
11090   ins_pipe(pipe_slow); // XXX
11091 %}
11092 
11093 instruct convXI2D_reg(regD dst, rRegI src)
11094 %{
11095   predicate(UseXmmI2D);
11096   match(Set dst (ConvI2D src));
11097 
11098   format %{ "movdl $dst, $src\n\t"
11099             "cvtdq2pdl $dst, $dst\t# i2d" %}
11100   ins_encode %{
11101     __ movdl($dst$$XMMRegister, $src$$Register);
11102     __ cvtdq2pd($dst$$XMMRegister, $dst$$XMMRegister);
11103   %}
11104   ins_pipe(pipe_slow); // XXX
11105 %}
11106 
11107 instruct convL2F_reg_reg(regF dst, rRegL src)
11108 %{
11109   match(Set dst (ConvL2F src));
11110 
11111   format %{ "cvtsi2ssq $dst, $src\t# l2f" %}
11112   opcode(0xF3, 0x0F, 0x2A);
11113   ins_encode(OpcP, REX_reg_reg_wide(dst, src), OpcS, OpcT, reg_reg(dst, src));
11114   ins_pipe(pipe_slow); // XXX
11115 %}
11116 
11117 instruct convL2F_reg_mem(regF dst, memory src)
11118 %{
11119   match(Set dst (ConvL2F (LoadL src)));
11120 
11121   format %{ "cvtsi2ssq $dst, $src\t# l2f" %}
11122   opcode(0xF3, 0x0F, 0x2A);
11123   ins_encode(OpcP, REX_reg_mem_wide(dst, src), OpcS, OpcT, reg_mem(dst, src));
11124   ins_pipe(pipe_slow); // XXX
11125 %}
11126 
11127 instruct convL2D_reg_reg(regD dst, rRegL src)
11128 %{
11129   match(Set dst (ConvL2D src));
11130 
11131   format %{ "cvtsi2sdq $dst, $src\t# l2d" %}
11132   opcode(0xF2, 0x0F, 0x2A);
11133   ins_encode(OpcP, REX_reg_reg_wide(dst, src), OpcS, OpcT, reg_reg(dst, src));
11134   ins_pipe(pipe_slow); // XXX
11135 %}
11136 
11137 instruct convL2D_reg_mem(regD dst, memory src)
11138 %{
11139   match(Set dst (ConvL2D (LoadL src)));
11140 
11141   format %{ "cvtsi2sdq $dst, $src\t# l2d" %}
11142   opcode(0xF2, 0x0F, 0x2A);
11143   ins_encode(OpcP, REX_reg_mem_wide(dst, src), OpcS, OpcT, reg_mem(dst, src));
11144   ins_pipe(pipe_slow); // XXX
11145 %}
11146 
11147 instruct convI2L_reg_reg(rRegL dst, rRegI src)
11148 %{
11149   match(Set dst (ConvI2L src));
11150 
11151   ins_cost(125);
11152   format %{ "movslq  $dst, $src\t# i2l" %}
11153   ins_encode %{
11154     __ movslq($dst$$Register, $src$$Register);
11155   %}
11156   ins_pipe(ialu_reg_reg);
11157 %}
11158 
11159 // instruct convI2L_reg_reg_foo(rRegL dst, rRegI src)
11160 // %{
11161 //   match(Set dst (ConvI2L src));
11162 // //   predicate(_kids[0]->_leaf->as_Type()->type()->is_int()->_lo >= 0 &&
11163 // //             _kids[0]->_leaf->as_Type()->type()->is_int()->_hi >= 0);
11164 //   predicate(((const TypeNode*) n)->type()->is_long()->_hi ==
11165 //             (unsigned int) ((const TypeNode*) n)->type()->is_long()->_hi &&
11166 //             ((const TypeNode*) n)->type()->is_long()->_lo ==
11167 //             (unsigned int) ((const TypeNode*) n)->type()->is_long()->_lo);
11168 
11169 //   format %{ "movl    $dst, $src\t# unsigned i2l" %}
11170 //   ins_encode(enc_copy(dst, src));
11171 // //   opcode(0x63); // needs REX.W
11172 // //   ins_encode(REX_reg_reg_wide(dst, src), OpcP, reg_reg(dst,src));
11173 //   ins_pipe(ialu_reg_reg);
11174 // %}
11175 
11176 // Zero-extend convert int to long
11177 instruct convI2L_reg_reg_zex(rRegL dst, rRegI src, immL_32bits mask)
11178 %{
11179   match(Set dst (AndL (ConvI2L src) mask));
11180 
11181   format %{ "movl    $dst, $src\t# i2l zero-extend\n\t" %}
11182   ins_encode(enc_copy(dst, src));
11183   ins_pipe(ialu_reg_reg);
11184 %}
11185 
11186 // Zero-extend convert int to long
11187 instruct convI2L_reg_mem_zex(rRegL dst, memory src, immL_32bits mask)
11188 %{
11189   match(Set dst (AndL (ConvI2L (LoadI src)) mask));
11190 
11191   format %{ "movl    $dst, $src\t# i2l zero-extend\n\t" %}
11192   opcode(0x8B);
11193   ins_encode(REX_reg_mem(dst, src), OpcP, reg_mem(dst, src));
11194   ins_pipe(ialu_reg_mem);
11195 %}
11196 
11197 instruct zerox_long_reg_reg(rRegL dst, rRegL src, immL_32bits mask)
11198 %{
11199   match(Set dst (AndL src mask));
11200 
11201   format %{ "movl    $dst, $src\t# zero-extend long" %}
11202   ins_encode(enc_copy_always(dst, src));
11203   ins_pipe(ialu_reg_reg);
11204 %}
11205 
11206 instruct convL2I_reg_reg(rRegI dst, rRegL src)
11207 %{
11208   match(Set dst (ConvL2I src));
11209 
11210   format %{ "movl    $dst, $src\t# l2i" %}
11211   ins_encode(enc_copy_always(dst, src));
11212   ins_pipe(ialu_reg_reg);
11213 %}
11214 
11215 
11216 instruct MoveF2I_stack_reg(rRegI dst, stackSlotF src) %{
11217   match(Set dst (MoveF2I src));
11218   effect(DEF dst, USE src);
11219 
11220   ins_cost(125);
11221   format %{ "movl    $dst, $src\t# MoveF2I_stack_reg" %}
11222   opcode(0x8B);
11223   ins_encode(REX_reg_mem(dst, src), OpcP, reg_mem(dst, src));
11224   ins_pipe(ialu_reg_mem);
11225 %}
11226 
11227 instruct MoveI2F_stack_reg(regF dst, stackSlotI src) %{
11228   match(Set dst (MoveI2F src));
11229   effect(DEF dst, USE src);
11230 
11231   ins_cost(125);
11232   format %{ "movss   $dst, $src\t# MoveI2F_stack_reg" %}
11233   opcode(0xF3, 0x0F, 0x10);
11234   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
11235   ins_pipe(pipe_slow);
11236 %}
11237 
11238 instruct MoveD2L_stack_reg(rRegL dst, stackSlotD src) %{
11239   match(Set dst (MoveD2L src));
11240   effect(DEF dst, USE src);
11241 
11242   ins_cost(125);
11243   format %{ "movq    $dst, $src\t# MoveD2L_stack_reg" %}
11244   opcode(0x8B);
11245   ins_encode(REX_reg_mem_wide(dst, src), OpcP, reg_mem(dst, src));
11246   ins_pipe(ialu_reg_mem);
11247 %}
11248 
11249 instruct MoveL2D_stack_reg_partial(regD dst, stackSlotL src) %{
11250   predicate(!UseXmmLoadAndClearUpper);
11251   match(Set dst (MoveL2D src));
11252   effect(DEF dst, USE src);
11253 
11254   ins_cost(125);
11255   format %{ "movlpd  $dst, $src\t# MoveL2D_stack_reg" %}
11256   opcode(0x66, 0x0F, 0x12);
11257   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
11258   ins_pipe(pipe_slow);
11259 %}
11260 
11261 instruct MoveL2D_stack_reg(regD dst, stackSlotL src) %{
11262   predicate(UseXmmLoadAndClearUpper);
11263   match(Set dst (MoveL2D src));
11264   effect(DEF dst, USE src);
11265 
11266   ins_cost(125);
11267   format %{ "movsd   $dst, $src\t# MoveL2D_stack_reg" %}
11268   opcode(0xF2, 0x0F, 0x10);
11269   ins_encode(OpcP, REX_reg_mem(dst, src), OpcS, OpcT, reg_mem(dst, src));
11270   ins_pipe(pipe_slow);
11271 %}
11272 
11273 
11274 instruct MoveF2I_reg_stack(stackSlotI dst, regF src) %{
11275   match(Set dst (MoveF2I src));
11276   effect(DEF dst, USE src);
11277 
11278   ins_cost(95); // XXX
11279   format %{ "movss   $dst, $src\t# MoveF2I_reg_stack" %}
11280   opcode(0xF3, 0x0F, 0x11);
11281   ins_encode(OpcP, REX_reg_mem(src, dst), OpcS, OpcT, reg_mem(src, dst));
11282   ins_pipe(pipe_slow);
11283 %}
11284 
11285 instruct MoveI2F_reg_stack(stackSlotF dst, rRegI src) %{
11286   match(Set dst (MoveI2F src));
11287   effect(DEF dst, USE src);
11288 
11289   ins_cost(100);
11290   format %{ "movl    $dst, $src\t# MoveI2F_reg_stack" %}
11291   opcode(0x89);
11292   ins_encode(REX_reg_mem(src, dst), OpcP, reg_mem(src, dst));
11293   ins_pipe( ialu_mem_reg );
11294 %}
11295 
11296 instruct MoveD2L_reg_stack(stackSlotL dst, regD src) %{
11297   match(Set dst (MoveD2L src));
11298   effect(DEF dst, USE src);
11299 
11300   ins_cost(95); // XXX
11301   format %{ "movsd   $dst, $src\t# MoveL2D_reg_stack" %}
11302   opcode(0xF2, 0x0F, 0x11);
11303   ins_encode(OpcP, REX_reg_mem(src, dst), OpcS, OpcT, reg_mem(src, dst));
11304   ins_pipe(pipe_slow);
11305 %}
11306 
11307 instruct MoveL2D_reg_stack(stackSlotD dst, rRegL src) %{
11308   match(Set dst (MoveL2D src));
11309   effect(DEF dst, USE src);
11310 
11311   ins_cost(100);
11312   format %{ "movq    $dst, $src\t# MoveL2D_reg_stack" %}
11313   opcode(0x89);
11314   ins_encode(REX_reg_mem_wide(src, dst), OpcP, reg_mem(src, dst));
11315   ins_pipe(ialu_mem_reg);
11316 %}
11317 
11318 instruct MoveF2I_reg_reg(rRegI dst, regF src) %{
11319   match(Set dst (MoveF2I src));
11320   effect(DEF dst, USE src);
11321   ins_cost(85);
11322   format %{ "movd    $dst,$src\t# MoveF2I" %}
11323   ins_encode %{ __ movdl($dst$$Register, $src$$XMMRegister); %}
11324   ins_pipe( pipe_slow );
11325 %}
11326 
11327 instruct MoveD2L_reg_reg(rRegL dst, regD src) %{
11328   match(Set dst (MoveD2L src));
11329   effect(DEF dst, USE src);
11330   ins_cost(85);
11331   format %{ "movd    $dst,$src\t# MoveD2L" %}
11332   ins_encode %{ __ movdq($dst$$Register, $src$$XMMRegister); %}
11333   ins_pipe( pipe_slow );
11334 %}
11335 
11336 // The next instructions have long latency and use Int unit. Set high cost.
11337 instruct MoveI2F_reg_reg(regF dst, rRegI src) %{
11338   match(Set dst (MoveI2F src));
11339   effect(DEF dst, USE src);
11340   ins_cost(300);
11341   format %{ "movd    $dst,$src\t# MoveI2F" %}
11342   ins_encode %{ __ movdl($dst$$XMMRegister, $src$$Register); %}
11343   ins_pipe( pipe_slow );
11344 %}
11345 
11346 instruct MoveL2D_reg_reg(regD dst, rRegL src) %{
11347   match(Set dst (MoveL2D src));
11348   effect(DEF dst, USE src);
11349   ins_cost(300);
11350   format %{ "movd    $dst,$src\t# MoveL2D" %}
11351   ins_encode %{ __ movdq($dst$$XMMRegister, $src$$Register); %}
11352   ins_pipe( pipe_slow );
11353 %}
11354 
11355 // Replicate scalar to packed byte (1 byte) values in xmm
11356 instruct Repl8B_reg(regD dst, regD src) %{
11357   match(Set dst (Replicate8B src));
11358   format %{ "MOVDQA  $dst,$src\n\t"
11359             "PUNPCKLBW $dst,$dst\n\t"
11360             "PSHUFLW $dst,$dst,0x00\t! replicate8B" %}
11361   ins_encode( pshufd_8x8(dst, src));
11362   ins_pipe( pipe_slow );
11363 %}
11364 
11365 // Replicate scalar to packed byte (1 byte) values in xmm
11366 instruct Repl8B_rRegI(regD dst, rRegI src) %{
11367   match(Set dst (Replicate8B src));
11368   format %{ "MOVD    $dst,$src\n\t"
11369             "PUNPCKLBW $dst,$dst\n\t"
11370             "PSHUFLW $dst,$dst,0x00\t! replicate8B" %}
11371   ins_encode( mov_i2x(dst, src), pshufd_8x8(dst, dst));
11372   ins_pipe( pipe_slow );
11373 %}
11374 
11375 // Replicate scalar zero to packed byte (1 byte) values in xmm
11376 instruct Repl8B_immI0(regD dst, immI0 zero) %{
11377   match(Set dst (Replicate8B zero));
11378   format %{ "PXOR  $dst,$dst\t! replicate8B" %}
11379   ins_encode( pxor(dst, dst));
11380   ins_pipe( fpu_reg_reg );
11381 %}
11382 
11383 // Replicate scalar to packed shore (2 byte) values in xmm
11384 instruct Repl4S_reg(regD dst, regD src) %{
11385   match(Set dst (Replicate4S src));
11386   format %{ "PSHUFLW $dst,$src,0x00\t! replicate4S" %}
11387   ins_encode( pshufd_4x16(dst, src));
11388   ins_pipe( fpu_reg_reg );
11389 %}
11390 
11391 // Replicate scalar to packed shore (2 byte) values in xmm
11392 instruct Repl4S_rRegI(regD dst, rRegI src) %{
11393   match(Set dst (Replicate4S src));
11394   format %{ "MOVD    $dst,$src\n\t"
11395             "PSHUFLW $dst,$dst,0x00\t! replicate4S" %}
11396   ins_encode( mov_i2x(dst, src), pshufd_4x16(dst, dst));
11397   ins_pipe( fpu_reg_reg );
11398 %}
11399 
11400 // Replicate scalar zero to packed short (2 byte) values in xmm
11401 instruct Repl4S_immI0(regD dst, immI0 zero) %{
11402   match(Set dst (Replicate4S zero));
11403   format %{ "PXOR  $dst,$dst\t! replicate4S" %}
11404   ins_encode( pxor(dst, dst));
11405   ins_pipe( fpu_reg_reg );
11406 %}
11407 
11408 // Replicate scalar to packed char (2 byte) values in xmm
11409 instruct Repl4C_reg(regD dst, regD src) %{
11410   match(Set dst (Replicate4C src));
11411   format %{ "PSHUFLW $dst,$src,0x00\t! replicate4C" %}
11412   ins_encode( pshufd_4x16(dst, src));
11413   ins_pipe( fpu_reg_reg );
11414 %}
11415 
11416 // Replicate scalar to packed char (2 byte) values in xmm
11417 instruct Repl4C_rRegI(regD dst, rRegI src) %{
11418   match(Set dst (Replicate4C src));
11419   format %{ "MOVD    $dst,$src\n\t"
11420             "PSHUFLW $dst,$dst,0x00\t! replicate4C" %}
11421   ins_encode( mov_i2x(dst, src), pshufd_4x16(dst, dst));
11422   ins_pipe( fpu_reg_reg );
11423 %}
11424 
11425 // Replicate scalar zero to packed char (2 byte) values in xmm
11426 instruct Repl4C_immI0(regD dst, immI0 zero) %{
11427   match(Set dst (Replicate4C zero));
11428   format %{ "PXOR  $dst,$dst\t! replicate4C" %}
11429   ins_encode( pxor(dst, dst));
11430   ins_pipe( fpu_reg_reg );
11431 %}
11432 
11433 // Replicate scalar to packed integer (4 byte) values in xmm
11434 instruct Repl2I_reg(regD dst, regD src) %{
11435   match(Set dst (Replicate2I src));
11436   format %{ "PSHUFD $dst,$src,0x00\t! replicate2I" %}
11437   ins_encode( pshufd(dst, src, 0x00));
11438   ins_pipe( fpu_reg_reg );
11439 %}
11440 
11441 // Replicate scalar to packed integer (4 byte) values in xmm
11442 instruct Repl2I_rRegI(regD dst, rRegI src) %{
11443   match(Set dst (Replicate2I src));
11444   format %{ "MOVD   $dst,$src\n\t"
11445             "PSHUFD $dst,$dst,0x00\t! replicate2I" %}
11446   ins_encode( mov_i2x(dst, src), pshufd(dst, dst, 0x00));
11447   ins_pipe( fpu_reg_reg );
11448 %}
11449 
11450 // Replicate scalar zero to packed integer (2 byte) values in xmm
11451 instruct Repl2I_immI0(regD dst, immI0 zero) %{
11452   match(Set dst (Replicate2I zero));
11453   format %{ "PXOR  $dst,$dst\t! replicate2I" %}
11454   ins_encode( pxor(dst, dst));
11455   ins_pipe( fpu_reg_reg );
11456 %}
11457 
11458 // Replicate scalar to packed single precision floating point values in xmm
11459 instruct Repl2F_reg(regD dst, regD src) %{
11460   match(Set dst (Replicate2F src));
11461   format %{ "PSHUFD $dst,$src,0xe0\t! replicate2F" %}
11462   ins_encode( pshufd(dst, src, 0xe0));
11463   ins_pipe( fpu_reg_reg );
11464 %}
11465 
11466 // Replicate scalar to packed single precision floating point values in xmm
11467 instruct Repl2F_regF(regD dst, regF src) %{
11468   match(Set dst (Replicate2F src));
11469   format %{ "PSHUFD $dst,$src,0xe0\t! replicate2F" %}
11470   ins_encode( pshufd(dst, src, 0xe0));
11471   ins_pipe( fpu_reg_reg );
11472 %}
11473 
11474 // Replicate scalar to packed single precision floating point values in xmm
11475 instruct Repl2F_immF0(regD dst, immF0 zero) %{
11476   match(Set dst (Replicate2F zero));
11477   format %{ "PXOR  $dst,$dst\t! replicate2F" %}
11478   ins_encode( pxor(dst, dst));
11479   ins_pipe( fpu_reg_reg );
11480 %}
11481 
11482 
11483 // =======================================================================
11484 // fast clearing of an array
11485 instruct rep_stos(rcx_RegL cnt, rdi_RegP base, rax_RegI zero, Universe dummy,
11486                   rFlagsReg cr)
11487 %{
11488   match(Set dummy (ClearArray cnt base));
11489   effect(USE_KILL cnt, USE_KILL base, KILL zero, KILL cr);
11490 
11491   format %{ "xorl    rax, rax\t# ClearArray:\n\t"
11492             "rep stosq\t# Store rax to *rdi++ while rcx--" %}
11493   ins_encode(opc_reg_reg(0x33, RAX, RAX), // xorl %eax, %eax
11494              Opcode(0xF3), Opcode(0x48), Opcode(0xAB)); // rep REX_W stos
11495   ins_pipe(pipe_slow);
11496 %}
11497 
11498 instruct string_compare(rdi_RegP str1, rcx_RegI cnt1, rsi_RegP str2, rdx_RegI cnt2,
11499                         rax_RegI result, regD tmp1, rFlagsReg cr)
11500 %{
11501   match(Set result (StrComp (Binary str1 cnt1) (Binary str2 cnt2)));
11502   effect(TEMP tmp1, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL cr);
11503 
11504   format %{ "String Compare $str1,$cnt1,$str2,$cnt2 -> $result   // KILL $tmp1" %}
11505   ins_encode %{
11506     __ string_compare($str1$$Register, $str2$$Register,
11507                       $cnt1$$Register, $cnt2$$Register, $result$$Register,
11508                       $tmp1$$XMMRegister);
11509   %}
11510   ins_pipe( pipe_slow );
11511 %}
11512 
11513 // fast search of substring with known size.
11514 instruct string_indexof_con(rdi_RegP str1, rdx_RegI cnt1, rsi_RegP str2, immI int_cnt2,
11515                             rbx_RegI result, regD vec, rax_RegI cnt2, rcx_RegI tmp, rFlagsReg cr)
11516 %{
11517   predicate(UseSSE42Intrinsics);
11518   match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 int_cnt2)));
11519   effect(TEMP vec, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, KILL cnt2, KILL tmp, KILL cr);
11520 
11521   format %{ "String IndexOf $str1,$cnt1,$str2,$int_cnt2 -> $result   // KILL $vec, $cnt1, $cnt2, $tmp" %}
11522   ins_encode %{
11523     int icnt2 = (int)$int_cnt2$$constant;
11524     if (icnt2 >= 8) {
11525       // IndexOf for constant substrings with size >= 8 elements
11526       // which don't need to be loaded through stack.
11527       __ string_indexofC8($str1$$Register, $str2$$Register,
11528                           $cnt1$$Register, $cnt2$$Register,
11529                           icnt2, $result$$Register,
11530                           $vec$$XMMRegister, $tmp$$Register);
11531     } else {
11532       // Small strings are loaded through stack if they cross page boundary.
11533       __ string_indexof($str1$$Register, $str2$$Register,
11534                         $cnt1$$Register, $cnt2$$Register,
11535                         icnt2, $result$$Register,
11536                         $vec$$XMMRegister, $tmp$$Register);
11537     }
11538   %}
11539   ins_pipe( pipe_slow );
11540 %}
11541 
11542 instruct string_indexof(rdi_RegP str1, rdx_RegI cnt1, rsi_RegP str2, rax_RegI cnt2,
11543                         rbx_RegI result, regD vec, rcx_RegI tmp, rFlagsReg cr)
11544 %{
11545   predicate(UseSSE42Intrinsics);
11546   match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 cnt2)));
11547   effect(TEMP vec, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL tmp, KILL cr);
11548 
11549   format %{ "String IndexOf $str1,$cnt1,$str2,$cnt2 -> $result   // KILL all" %}
11550   ins_encode %{
11551     __ string_indexof($str1$$Register, $str2$$Register,
11552                       $cnt1$$Register, $cnt2$$Register,
11553                       (-1), $result$$Register,
11554                       $vec$$XMMRegister, $tmp$$Register);
11555   %}
11556   ins_pipe( pipe_slow );
11557 %}
11558 
11559 // fast string equals
11560 instruct string_equals(rdi_RegP str1, rsi_RegP str2, rcx_RegI cnt, rax_RegI result,
11561                        regD tmp1, regD tmp2, rbx_RegI tmp3, rFlagsReg cr)
11562 %{
11563   match(Set result (StrEquals (Binary str1 str2) cnt));
11564   effect(TEMP tmp1, TEMP tmp2, USE_KILL str1, USE_KILL str2, USE_KILL cnt, KILL tmp3, KILL cr);
11565 
11566   format %{ "String Equals $str1,$str2,$cnt -> $result    // KILL $tmp1, $tmp2, $tmp3" %}
11567   ins_encode %{
11568     __ char_arrays_equals(false, $str1$$Register, $str2$$Register,
11569                           $cnt$$Register, $result$$Register, $tmp3$$Register,
11570                           $tmp1$$XMMRegister, $tmp2$$XMMRegister);
11571   %}
11572   ins_pipe( pipe_slow );
11573 %}
11574 
11575 // fast array equals
11576 instruct array_equals(rdi_RegP ary1, rsi_RegP ary2, rax_RegI result,
11577                       regD tmp1, regD tmp2, rcx_RegI tmp3, rbx_RegI tmp4, rFlagsReg cr)
11578 %{
11579   match(Set result (AryEq ary1 ary2));
11580   effect(TEMP tmp1, TEMP tmp2, USE_KILL ary1, USE_KILL ary2, KILL tmp3, KILL tmp4, KILL cr);
11581   //ins_cost(300);
11582 
11583   format %{ "Array Equals $ary1,$ary2 -> $result   // KILL $tmp1, $tmp2, $tmp3, $tmp4" %}
11584   ins_encode %{
11585     __ char_arrays_equals(true, $ary1$$Register, $ary2$$Register,
11586                           $tmp3$$Register, $result$$Register, $tmp4$$Register,
11587                           $tmp1$$XMMRegister, $tmp2$$XMMRegister);
11588   %}
11589   ins_pipe( pipe_slow );
11590 %}
11591 
11592 //----------Control Flow Instructions------------------------------------------
11593 // Signed compare Instructions
11594 
11595 // XXX more variants!!
11596 instruct compI_rReg(rFlagsReg cr, rRegI op1, rRegI op2)
11597 %{
11598   match(Set cr (CmpI op1 op2));
11599   effect(DEF cr, USE op1, USE op2);
11600 
11601   format %{ "cmpl    $op1, $op2" %}
11602   opcode(0x3B);  /* Opcode 3B /r */
11603   ins_encode(REX_reg_reg(op1, op2), OpcP, reg_reg(op1, op2));
11604   ins_pipe(ialu_cr_reg_reg);
11605 %}
11606 
11607 instruct compI_rReg_imm(rFlagsReg cr, rRegI op1, immI op2)
11608 %{
11609   match(Set cr (CmpI op1 op2));
11610 
11611   format %{ "cmpl    $op1, $op2" %}
11612   opcode(0x81, 0x07); /* Opcode 81 /7 */
11613   ins_encode(OpcSErm(op1, op2), Con8or32(op2));
11614   ins_pipe(ialu_cr_reg_imm);
11615 %}
11616 
11617 instruct compI_rReg_mem(rFlagsReg cr, rRegI op1, memory op2)
11618 %{
11619   match(Set cr (CmpI op1 (LoadI op2)));
11620 
11621   ins_cost(500); // XXX
11622   format %{ "cmpl    $op1, $op2" %}
11623   opcode(0x3B); /* Opcode 3B /r */
11624   ins_encode(REX_reg_mem(op1, op2), OpcP, reg_mem(op1, op2));
11625   ins_pipe(ialu_cr_reg_mem);
11626 %}
11627 
11628 instruct testI_reg(rFlagsReg cr, rRegI src, immI0 zero)
11629 %{
11630   match(Set cr (CmpI src zero));
11631 
11632   format %{ "testl   $src, $src" %}
11633   opcode(0x85);
11634   ins_encode(REX_reg_reg(src, src), OpcP, reg_reg(src, src));
11635   ins_pipe(ialu_cr_reg_imm);
11636 %}
11637 
11638 instruct testI_reg_imm(rFlagsReg cr, rRegI src, immI con, immI0 zero)
11639 %{
11640   match(Set cr (CmpI (AndI src con) zero));
11641 
11642   format %{ "testl   $src, $con" %}
11643   opcode(0xF7, 0x00);
11644   ins_encode(REX_reg(src), OpcP, reg_opc(src), Con32(con));
11645   ins_pipe(ialu_cr_reg_imm);
11646 %}
11647 
11648 instruct testI_reg_mem(rFlagsReg cr, rRegI src, memory mem, immI0 zero)
11649 %{
11650   match(Set cr (CmpI (AndI src (LoadI mem)) zero));
11651 
11652   format %{ "testl   $src, $mem" %}
11653   opcode(0x85);
11654   ins_encode(REX_reg_mem(src, mem), OpcP, reg_mem(src, mem));
11655   ins_pipe(ialu_cr_reg_mem);
11656 %}
11657 
11658 // Unsigned compare Instructions; really, same as signed except they
11659 // produce an rFlagsRegU instead of rFlagsReg.
11660 instruct compU_rReg(rFlagsRegU cr, rRegI op1, rRegI op2)
11661 %{
11662   match(Set cr (CmpU op1 op2));
11663 
11664   format %{ "cmpl    $op1, $op2\t# unsigned" %}
11665   opcode(0x3B); /* Opcode 3B /r */
11666   ins_encode(REX_reg_reg(op1, op2), OpcP, reg_reg(op1, op2));
11667   ins_pipe(ialu_cr_reg_reg);
11668 %}
11669 
11670 instruct compU_rReg_imm(rFlagsRegU cr, rRegI op1, immI op2)
11671 %{
11672   match(Set cr (CmpU op1 op2));
11673 
11674   format %{ "cmpl    $op1, $op2\t# unsigned" %}
11675   opcode(0x81,0x07); /* Opcode 81 /7 */
11676   ins_encode(OpcSErm(op1, op2), Con8or32(op2));
11677   ins_pipe(ialu_cr_reg_imm);
11678 %}
11679 
11680 instruct compU_rReg_mem(rFlagsRegU cr, rRegI op1, memory op2)
11681 %{
11682   match(Set cr (CmpU op1 (LoadI op2)));
11683 
11684   ins_cost(500); // XXX
11685   format %{ "cmpl    $op1, $op2\t# unsigned" %}
11686   opcode(0x3B); /* Opcode 3B /r */
11687   ins_encode(REX_reg_mem(op1, op2), OpcP, reg_mem(op1, op2));
11688   ins_pipe(ialu_cr_reg_mem);
11689 %}
11690 
11691 // // // Cisc-spilled version of cmpU_rReg
11692 // //instruct compU_mem_rReg(rFlagsRegU cr, memory op1, rRegI op2)
11693 // //%{
11694 // //  match(Set cr (CmpU (LoadI op1) op2));
11695 // //
11696 // //  format %{ "CMPu   $op1,$op2" %}
11697 // //  ins_cost(500);
11698 // //  opcode(0x39);  /* Opcode 39 /r */
11699 // //  ins_encode( OpcP, reg_mem( op1, op2) );
11700 // //%}
11701 
11702 instruct testU_reg(rFlagsRegU cr, rRegI src, immI0 zero)
11703 %{
11704   match(Set cr (CmpU src zero));
11705 
11706   format %{ "testl  $src, $src\t# unsigned" %}
11707   opcode(0x85);
11708   ins_encode(REX_reg_reg(src, src), OpcP, reg_reg(src, src));
11709   ins_pipe(ialu_cr_reg_imm);
11710 %}
11711 
11712 instruct compP_rReg(rFlagsRegU cr, rRegP op1, rRegP op2)
11713 %{
11714   match(Set cr (CmpP op1 op2));
11715 
11716   format %{ "cmpq    $op1, $op2\t# ptr" %}
11717   opcode(0x3B); /* Opcode 3B /r */
11718   ins_encode(REX_reg_reg_wide(op1, op2), OpcP, reg_reg(op1, op2));
11719   ins_pipe(ialu_cr_reg_reg);
11720 %}
11721 
11722 instruct compP_rReg_mem(rFlagsRegU cr, rRegP op1, memory op2)
11723 %{
11724   match(Set cr (CmpP op1 (LoadP op2)));
11725 
11726   ins_cost(500); // XXX
11727   format %{ "cmpq    $op1, $op2\t# ptr" %}
11728   opcode(0x3B); /* Opcode 3B /r */
11729   ins_encode(REX_reg_mem_wide(op1, op2), OpcP, reg_mem(op1, op2));
11730   ins_pipe(ialu_cr_reg_mem);
11731 %}
11732 
11733 // // // Cisc-spilled version of cmpP_rReg
11734 // //instruct compP_mem_rReg(rFlagsRegU cr, memory op1, rRegP op2)
11735 // //%{
11736 // //  match(Set cr (CmpP (LoadP op1) op2));
11737 // //
11738 // //  format %{ "CMPu   $op1,$op2" %}
11739 // //  ins_cost(500);
11740 // //  opcode(0x39);  /* Opcode 39 /r */
11741 // //  ins_encode( OpcP, reg_mem( op1, op2) );
11742 // //%}
11743 
11744 // XXX this is generalized by compP_rReg_mem???
11745 // Compare raw pointer (used in out-of-heap check).
11746 // Only works because non-oop pointers must be raw pointers
11747 // and raw pointers have no anti-dependencies.
11748 instruct compP_mem_rReg(rFlagsRegU cr, rRegP op1, memory op2)
11749 %{
11750   predicate(!n->in(2)->in(2)->bottom_type()->isa_oop_ptr());
11751   match(Set cr (CmpP op1 (LoadP op2)));
11752 
11753   format %{ "cmpq    $op1, $op2\t# raw ptr" %}
11754   opcode(0x3B); /* Opcode 3B /r */
11755   ins_encode(REX_reg_mem_wide(op1, op2), OpcP, reg_mem(op1, op2));
11756   ins_pipe(ialu_cr_reg_mem);
11757 %}
11758 
11759 // This will generate a signed flags result. This should be OK since
11760 // any compare to a zero should be eq/neq.
11761 instruct testP_reg(rFlagsReg cr, rRegP src, immP0 zero)
11762 %{
11763   match(Set cr (CmpP src zero));
11764 
11765   format %{ "testq   $src, $src\t# ptr" %}
11766   opcode(0x85);
11767   ins_encode(REX_reg_reg_wide(src, src), OpcP, reg_reg(src, src));
11768   ins_pipe(ialu_cr_reg_imm);
11769 %}
11770 
11771 // This will generate a signed flags result. This should be OK since
11772 // any compare to a zero should be eq/neq.
11773 instruct testP_mem(rFlagsReg cr, memory op, immP0 zero)
11774 %{
11775   predicate(!UseCompressedOops || (Universe::narrow_oop_base() != NULL));
11776   match(Set cr (CmpP (LoadP op) zero));
11777 
11778   ins_cost(500); // XXX
11779   format %{ "testq   $op, 0xffffffffffffffff\t# ptr" %}
11780   opcode(0xF7); /* Opcode F7 /0 */
11781   ins_encode(REX_mem_wide(op),
11782              OpcP, RM_opc_mem(0x00, op), Con_d32(0xFFFFFFFF));
11783   ins_pipe(ialu_cr_reg_imm);
11784 %}
11785 
11786 instruct testP_mem_reg0(rFlagsReg cr, memory mem, immP0 zero)
11787 %{
11788   predicate(UseCompressedOops && (Universe::narrow_oop_base() == NULL));
11789   match(Set cr (CmpP (LoadP mem) zero));
11790 
11791   format %{ "cmpq    R12, $mem\t# ptr (R12_heapbase==0)" %}
11792   ins_encode %{
11793     __ cmpq(r12, $mem$$Address);
11794   %}
11795   ins_pipe(ialu_cr_reg_mem);
11796 %}
11797 
11798 instruct compN_rReg(rFlagsRegU cr, rRegN op1, rRegN op2)
11799 %{
11800   match(Set cr (CmpN op1 op2));
11801 
11802   format %{ "cmpl    $op1, $op2\t# compressed ptr" %}
11803   ins_encode %{ __ cmpl($op1$$Register, $op2$$Register); %}
11804   ins_pipe(ialu_cr_reg_reg);
11805 %}
11806 
11807 instruct compN_rReg_mem(rFlagsRegU cr, rRegN src, memory mem)
11808 %{
11809   match(Set cr (CmpN src (LoadN mem)));
11810 
11811   format %{ "cmpl    $src, $mem\t# compressed ptr" %}
11812   ins_encode %{
11813     __ cmpl($src$$Register, $mem$$Address);
11814   %}
11815   ins_pipe(ialu_cr_reg_mem);
11816 %}
11817 
11818 instruct compN_rReg_imm(rFlagsRegU cr, rRegN op1, immN op2) %{
11819   match(Set cr (CmpN op1 op2));
11820 
11821   format %{ "cmpl    $op1, $op2\t# compressed ptr" %}
11822   ins_encode %{
11823     __ cmp_narrow_oop($op1$$Register, (jobject)$op2$$constant);
11824   %}
11825   ins_pipe(ialu_cr_reg_imm);
11826 %}
11827 
11828 instruct compN_mem_imm(rFlagsRegU cr, memory mem, immN src)
11829 %{
11830   match(Set cr (CmpN src (LoadN mem)));
11831 
11832   format %{ "cmpl    $mem, $src\t# compressed ptr" %}
11833   ins_encode %{
11834     __ cmp_narrow_oop($mem$$Address, (jobject)$src$$constant);
11835   %}
11836   ins_pipe(ialu_cr_reg_mem);
11837 %}
11838 
11839 instruct testN_reg(rFlagsReg cr, rRegN src, immN0 zero) %{
11840   match(Set cr (CmpN src zero));
11841 
11842   format %{ "testl   $src, $src\t# compressed ptr" %}
11843   ins_encode %{ __ testl($src$$Register, $src$$Register); %}
11844   ins_pipe(ialu_cr_reg_imm);
11845 %}
11846 
11847 instruct testN_mem(rFlagsReg cr, memory mem, immN0 zero)
11848 %{
11849   predicate(Universe::narrow_oop_base() != NULL);
11850   match(Set cr (CmpN (LoadN mem) zero));
11851 
11852   ins_cost(500); // XXX
11853   format %{ "testl   $mem, 0xffffffff\t# compressed ptr" %}
11854   ins_encode %{
11855     __ cmpl($mem$$Address, (int)0xFFFFFFFF);
11856   %}
11857   ins_pipe(ialu_cr_reg_mem);
11858 %}
11859 
11860 instruct testN_mem_reg0(rFlagsReg cr, memory mem, immN0 zero)
11861 %{
11862   predicate(Universe::narrow_oop_base() == NULL);
11863   match(Set cr (CmpN (LoadN mem) zero));
11864 
11865   format %{ "cmpl    R12, $mem\t# compressed ptr (R12_heapbase==0)" %}
11866   ins_encode %{
11867     __ cmpl(r12, $mem$$Address);
11868   %}
11869   ins_pipe(ialu_cr_reg_mem);
11870 %}
11871 
11872 // Yanked all unsigned pointer compare operations.
11873 // Pointer compares are done with CmpP which is already unsigned.
11874 
11875 instruct compL_rReg(rFlagsReg cr, rRegL op1, rRegL op2)
11876 %{
11877   match(Set cr (CmpL op1 op2));
11878 
11879   format %{ "cmpq    $op1, $op2" %}
11880   opcode(0x3B);  /* Opcode 3B /r */
11881   ins_encode(REX_reg_reg_wide(op1, op2), OpcP, reg_reg(op1, op2));
11882   ins_pipe(ialu_cr_reg_reg);
11883 %}
11884 
11885 instruct compL_rReg_imm(rFlagsReg cr, rRegL op1, immL32 op2)
11886 %{
11887   match(Set cr (CmpL op1 op2));
11888 
11889   format %{ "cmpq    $op1, $op2" %}
11890   opcode(0x81, 0x07); /* Opcode 81 /7 */
11891   ins_encode(OpcSErm_wide(op1, op2), Con8or32(op2));
11892   ins_pipe(ialu_cr_reg_imm);
11893 %}
11894 
11895 instruct compL_rReg_mem(rFlagsReg cr, rRegL op1, memory op2)
11896 %{
11897   match(Set cr (CmpL op1 (LoadL op2)));
11898 
11899   format %{ "cmpq    $op1, $op2" %}
11900   opcode(0x3B); /* Opcode 3B /r */
11901   ins_encode(REX_reg_mem_wide(op1, op2), OpcP, reg_mem(op1, op2));
11902   ins_pipe(ialu_cr_reg_mem);
11903 %}
11904 
11905 instruct testL_reg(rFlagsReg cr, rRegL src, immL0 zero)
11906 %{
11907   match(Set cr (CmpL src zero));
11908 
11909   format %{ "testq   $src, $src" %}
11910   opcode(0x85);
11911   ins_encode(REX_reg_reg_wide(src, src), OpcP, reg_reg(src, src));
11912   ins_pipe(ialu_cr_reg_imm);
11913 %}
11914 
11915 instruct testL_reg_imm(rFlagsReg cr, rRegL src, immL32 con, immL0 zero)
11916 %{
11917   match(Set cr (CmpL (AndL src con) zero));
11918 
11919   format %{ "testq   $src, $con\t# long" %}
11920   opcode(0xF7, 0x00);
11921   ins_encode(REX_reg_wide(src), OpcP, reg_opc(src), Con32(con));
11922   ins_pipe(ialu_cr_reg_imm);
11923 %}
11924 
11925 instruct testL_reg_mem(rFlagsReg cr, rRegL src, memory mem, immL0 zero)
11926 %{
11927   match(Set cr (CmpL (AndL src (LoadL mem)) zero));
11928 
11929   format %{ "testq   $src, $mem" %}
11930   opcode(0x85);
11931   ins_encode(REX_reg_mem_wide(src, mem), OpcP, reg_mem(src, mem));
11932   ins_pipe(ialu_cr_reg_mem);
11933 %}
11934 
11935 // Manifest a CmpL result in an integer register.  Very painful.
11936 // This is the test to avoid.
11937 instruct cmpL3_reg_reg(rRegI dst, rRegL src1, rRegL src2, rFlagsReg flags)
11938 %{
11939   match(Set dst (CmpL3 src1 src2));
11940   effect(KILL flags);
11941 
11942   ins_cost(275); // XXX
11943   format %{ "cmpq    $src1, $src2\t# CmpL3\n\t"
11944             "movl    $dst, -1\n\t"
11945             "jl,s    done\n\t"
11946             "setne   $dst\n\t"
11947             "movzbl  $dst, $dst\n\t"
11948     "done:" %}
11949   ins_encode(cmpl3_flag(src1, src2, dst));
11950   ins_pipe(pipe_slow);
11951 %}
11952 
11953 //----------Max and Min--------------------------------------------------------
11954 // Min Instructions
11955 
11956 instruct cmovI_reg_g(rRegI dst, rRegI src, rFlagsReg cr)
11957 %{
11958   effect(USE_DEF dst, USE src, USE cr);
11959 
11960   format %{ "cmovlgt $dst, $src\t# min" %}
11961   opcode(0x0F, 0x4F);
11962   ins_encode(REX_reg_reg(dst, src), OpcP, OpcS, reg_reg(dst, src));
11963   ins_pipe(pipe_cmov_reg);
11964 %}
11965 
11966 
11967 instruct minI_rReg(rRegI dst, rRegI src)
11968 %{
11969   match(Set dst (MinI dst src));
11970 
11971   ins_cost(200);
11972   expand %{
11973     rFlagsReg cr;
11974     compI_rReg(cr, dst, src);
11975     cmovI_reg_g(dst, src, cr);
11976   %}
11977 %}
11978 
11979 instruct cmovI_reg_l(rRegI dst, rRegI src, rFlagsReg cr)
11980 %{
11981   effect(USE_DEF dst, USE src, USE cr);
11982 
11983   format %{ "cmovllt $dst, $src\t# max" %}
11984   opcode(0x0F, 0x4C);
11985   ins_encode(REX_reg_reg(dst, src), OpcP, OpcS, reg_reg(dst, src));
11986   ins_pipe(pipe_cmov_reg);
11987 %}
11988 
11989 
11990 instruct maxI_rReg(rRegI dst, rRegI src)
11991 %{
11992   match(Set dst (MaxI dst src));
11993 
11994   ins_cost(200);
11995   expand %{
11996     rFlagsReg cr;
11997     compI_rReg(cr, dst, src);
11998     cmovI_reg_l(dst, src, cr);
11999   %}
12000 %}
12001 
12002 // ============================================================================
12003 // Branch Instructions
12004 
12005 // Jump Direct - Label defines a relative address from JMP+1
12006 instruct jmpDir(label labl)
12007 %{
12008   match(Goto);
12009   effect(USE labl);
12010 
12011   ins_cost(300);
12012   format %{ "jmp     $labl" %}
12013   size(5);
12014   opcode(0xE9);
12015   ins_encode(OpcP, Lbl(labl));
12016   ins_pipe(pipe_jmp);
12017 %}
12018 
12019 // Jump Direct Conditional - Label defines a relative address from Jcc+1
12020 instruct jmpCon(cmpOp cop, rFlagsReg cr, label labl)
12021 %{
12022   match(If cop cr);
12023   effect(USE labl);
12024 
12025   ins_cost(300);
12026   format %{ "j$cop     $labl" %}
12027   size(6);
12028   opcode(0x0F, 0x80);
12029   ins_encode(Jcc(cop, labl));
12030   ins_pipe(pipe_jcc);
12031 %}
12032 
12033 // Jump Direct Conditional - Label defines a relative address from Jcc+1
12034 instruct jmpLoopEnd(cmpOp cop, rFlagsReg cr, label labl)
12035 %{
12036   match(CountedLoopEnd cop cr);
12037   effect(USE labl);
12038 
12039   ins_cost(300);
12040   format %{ "j$cop     $labl\t# loop end" %}
12041   size(6);
12042   opcode(0x0F, 0x80);
12043   ins_encode(Jcc(cop, labl));
12044   ins_pipe(pipe_jcc);
12045 %}
12046 
12047 // Jump Direct Conditional - Label defines a relative address from Jcc+1
12048 instruct jmpLoopEndU(cmpOpU cop, rFlagsRegU cmp, label labl) %{
12049   match(CountedLoopEnd cop cmp);
12050   effect(USE labl);
12051 
12052   ins_cost(300);
12053   format %{ "j$cop,u   $labl\t# loop end" %}
12054   size(6);
12055   opcode(0x0F, 0x80);
12056   ins_encode(Jcc(cop, labl));
12057   ins_pipe(pipe_jcc);
12058 %}
12059 
12060 instruct jmpLoopEndUCF(cmpOpUCF cop, rFlagsRegUCF cmp, label labl) %{
12061   match(CountedLoopEnd cop cmp);
12062   effect(USE labl);
12063 
12064   ins_cost(200);
12065   format %{ "j$cop,u   $labl\t# loop end" %}
12066   size(6);
12067   opcode(0x0F, 0x80);
12068   ins_encode(Jcc(cop, labl));
12069   ins_pipe(pipe_jcc);
12070 %}
12071 
12072 // Jump Direct Conditional - using unsigned comparison
12073 instruct jmpConU(cmpOpU cop, rFlagsRegU cmp, label labl) %{
12074   match(If cop cmp);
12075   effect(USE labl);
12076 
12077   ins_cost(300);
12078   format %{ "j$cop,u  $labl" %}
12079   size(6);
12080   opcode(0x0F, 0x80);
12081   ins_encode(Jcc(cop, labl));
12082   ins_pipe(pipe_jcc);
12083 %}
12084 
12085 instruct jmpConUCF(cmpOpUCF cop, rFlagsRegUCF cmp, label labl) %{
12086   match(If cop cmp);
12087   effect(USE labl);
12088 
12089   ins_cost(200);
12090   format %{ "j$cop,u  $labl" %}
12091   size(6);
12092   opcode(0x0F, 0x80);
12093   ins_encode(Jcc(cop, labl));
12094   ins_pipe(pipe_jcc);
12095 %}
12096 
12097 instruct jmpConUCF2(cmpOpUCF2 cop, rFlagsRegUCF cmp, label labl) %{
12098   match(If cop cmp);
12099   effect(USE labl);
12100 
12101   ins_cost(200);
12102   format %{ $$template
12103     if ($cop$$cmpcode == Assembler::notEqual) {
12104       $$emit$$"jp,u   $labl\n\t"
12105       $$emit$$"j$cop,u   $labl"
12106     } else {
12107       $$emit$$"jp,u   done\n\t"
12108       $$emit$$"j$cop,u   $labl\n\t"
12109       $$emit$$"done:"
12110     }
12111   %}
12112   size(12);
12113   opcode(0x0F, 0x80);
12114   ins_encode %{
12115     Label* l = $labl$$label;
12116     $$$emit8$primary;
12117     emit_cc(cbuf, $secondary, Assembler::parity);
12118     int parity_disp = -1;
12119     if ($cop$$cmpcode == Assembler::notEqual) {
12120        // the two jumps 6 bytes apart so the jump distances are too
12121        parity_disp = l->loc_pos() - (cbuf.insts_size() + 4);
12122     } else if ($cop$$cmpcode == Assembler::equal) {
12123        parity_disp = 6;
12124     } else {
12125        ShouldNotReachHere();
12126     }
12127     emit_d32(cbuf, parity_disp);
12128     $$$emit8$primary;
12129     emit_cc(cbuf, $secondary, $cop$$cmpcode);
12130     int disp = l->loc_pos() - (cbuf.insts_size() + 4);
12131     emit_d32(cbuf, disp);
12132   %}
12133   ins_pipe(pipe_jcc);
12134 %}
12135 
12136 // ============================================================================
12137 // The 2nd slow-half of a subtype check.  Scan the subklass's 2ndary
12138 // superklass array for an instance of the superklass.  Set a hidden
12139 // internal cache on a hit (cache is checked with exposed code in
12140 // gen_subtype_check()).  Return NZ for a miss or zero for a hit.  The
12141 // encoding ALSO sets flags.
12142 
12143 instruct partialSubtypeCheck(rdi_RegP result,
12144                              rsi_RegP sub, rax_RegP super, rcx_RegI rcx,
12145                              rFlagsReg cr)
12146 %{
12147   match(Set result (PartialSubtypeCheck sub super));
12148   effect(KILL rcx, KILL cr);
12149 
12150   ins_cost(1100);  // slightly larger than the next version
12151   format %{ "movq    rdi, [$sub + (sizeof(oopDesc) + Klass::secondary_supers_offset_in_bytes())]\n\t"
12152             "movl    rcx, [rdi + arrayOopDesc::length_offset_in_bytes()]\t# length to scan\n\t"
12153             "addq    rdi, arrayOopDex::base_offset_in_bytes(T_OBJECT)\t# Skip to start of data; set NZ in case count is zero\n\t"
12154             "repne   scasq\t# Scan *rdi++ for a match with rax while rcx--\n\t"
12155             "jne,s   miss\t\t# Missed: rdi not-zero\n\t"
12156             "movq    [$sub + (sizeof(oopDesc) + Klass::secondary_super_cache_offset_in_bytes())], $super\t# Hit: update cache\n\t"
12157             "xorq    $result, $result\t\t Hit: rdi zero\n\t"
12158     "miss:\t" %}
12159 
12160   opcode(0x1); // Force a XOR of RDI
12161   ins_encode(enc_PartialSubtypeCheck());
12162   ins_pipe(pipe_slow);
12163 %}
12164 
12165 instruct partialSubtypeCheck_vs_Zero(rFlagsReg cr,
12166                                      rsi_RegP sub, rax_RegP super, rcx_RegI rcx,
12167                                      immP0 zero,
12168                                      rdi_RegP result)
12169 %{
12170   match(Set cr (CmpP (PartialSubtypeCheck sub super) zero));
12171   effect(KILL rcx, KILL result);
12172 
12173   ins_cost(1000);
12174   format %{ "movq    rdi, [$sub + (sizeof(oopDesc) + Klass::secondary_supers_offset_in_bytes())]\n\t"
12175             "movl    rcx, [rdi + arrayOopDesc::length_offset_in_bytes()]\t# length to scan\n\t"
12176             "addq    rdi, arrayOopDex::base_offset_in_bytes(T_OBJECT)\t# Skip to start of data; set NZ in case count is zero\n\t"
12177             "repne   scasq\t# Scan *rdi++ for a match with rax while cx-- != 0\n\t"
12178             "jne,s   miss\t\t# Missed: flags nz\n\t"
12179             "movq    [$sub + (sizeof(oopDesc) + Klass::secondary_super_cache_offset_in_bytes())], $super\t# Hit: update cache\n\t"
12180     "miss:\t" %}
12181 
12182   opcode(0x0); // No need to XOR RDI
12183   ins_encode(enc_PartialSubtypeCheck());
12184   ins_pipe(pipe_slow);
12185 %}
12186 
12187 // ============================================================================
12188 // Branch Instructions -- short offset versions
12189 //
12190 // These instructions are used to replace jumps of a long offset (the default
12191 // match) with jumps of a shorter offset.  These instructions are all tagged
12192 // with the ins_short_branch attribute, which causes the ADLC to suppress the
12193 // match rules in general matching.  Instead, the ADLC generates a conversion
12194 // method in the MachNode which can be used to do in-place replacement of the
12195 // long variant with the shorter variant.  The compiler will determine if a
12196 // branch can be taken by the is_short_branch_offset() predicate in the machine
12197 // specific code section of the file.
12198 
12199 // Jump Direct - Label defines a relative address from JMP+1
12200 instruct jmpDir_short(label labl) %{
12201   match(Goto);
12202   effect(USE labl);
12203 
12204   ins_cost(300);
12205   format %{ "jmp,s   $labl" %}
12206   size(2);
12207   opcode(0xEB);
12208   ins_encode(OpcP, LblShort(labl));
12209   ins_pipe(pipe_jmp);
12210   ins_short_branch(1);
12211 %}
12212 
12213 // Jump Direct Conditional - Label defines a relative address from Jcc+1
12214 instruct jmpCon_short(cmpOp cop, rFlagsReg cr, label labl) %{
12215   match(If cop cr);
12216   effect(USE labl);
12217 
12218   ins_cost(300);
12219   format %{ "j$cop,s   $labl" %}
12220   size(2);
12221   opcode(0x70);
12222   ins_encode(JccShort(cop, labl));
12223   ins_pipe(pipe_jcc);
12224   ins_short_branch(1);
12225 %}
12226 
12227 // Jump Direct Conditional - Label defines a relative address from Jcc+1
12228 instruct jmpLoopEnd_short(cmpOp cop, rFlagsReg cr, label labl) %{
12229   match(CountedLoopEnd cop cr);
12230   effect(USE labl);
12231 
12232   ins_cost(300);
12233   format %{ "j$cop,s   $labl\t# loop end" %}
12234   size(2);
12235   opcode(0x70);
12236   ins_encode(JccShort(cop, labl));
12237   ins_pipe(pipe_jcc);
12238   ins_short_branch(1);
12239 %}
12240 
12241 // Jump Direct Conditional - Label defines a relative address from Jcc+1
12242 instruct jmpLoopEndU_short(cmpOpU cop, rFlagsRegU cmp, label labl) %{
12243   match(CountedLoopEnd cop cmp);
12244   effect(USE labl);
12245 
12246   ins_cost(300);
12247   format %{ "j$cop,us  $labl\t# loop end" %}
12248   size(2);
12249   opcode(0x70);
12250   ins_encode(JccShort(cop, labl));
12251   ins_pipe(pipe_jcc);
12252   ins_short_branch(1);
12253 %}
12254 
12255 instruct jmpLoopEndUCF_short(cmpOpUCF cop, rFlagsRegUCF cmp, label labl) %{
12256   match(CountedLoopEnd cop cmp);
12257   effect(USE labl);
12258 
12259   ins_cost(300);
12260   format %{ "j$cop,us  $labl\t# loop end" %}
12261   size(2);
12262   opcode(0x70);
12263   ins_encode(JccShort(cop, labl));
12264   ins_pipe(pipe_jcc);
12265   ins_short_branch(1);
12266 %}
12267 
12268 // Jump Direct Conditional - using unsigned comparison
12269 instruct jmpConU_short(cmpOpU cop, rFlagsRegU cmp, label labl) %{
12270   match(If cop cmp);
12271   effect(USE labl);
12272 
12273   ins_cost(300);
12274   format %{ "j$cop,us  $labl" %}
12275   size(2);
12276   opcode(0x70);
12277   ins_encode(JccShort(cop, labl));
12278   ins_pipe(pipe_jcc);
12279   ins_short_branch(1);
12280 %}
12281 
12282 instruct jmpConUCF_short(cmpOpUCF cop, rFlagsRegUCF cmp, label labl) %{
12283   match(If cop cmp);
12284   effect(USE labl);
12285 
12286   ins_cost(300);
12287   format %{ "j$cop,us  $labl" %}
12288   size(2);
12289   opcode(0x70);
12290   ins_encode(JccShort(cop, labl));
12291   ins_pipe(pipe_jcc);
12292   ins_short_branch(1);
12293 %}
12294 
12295 instruct jmpConUCF2_short(cmpOpUCF2 cop, rFlagsRegUCF cmp, label labl) %{
12296   match(If cop cmp);
12297   effect(USE labl);
12298 
12299   ins_cost(300);
12300   format %{ $$template
12301     if ($cop$$cmpcode == Assembler::notEqual) {
12302       $$emit$$"jp,u,s   $labl\n\t"
12303       $$emit$$"j$cop,u,s   $labl"
12304     } else {
12305       $$emit$$"jp,u,s   done\n\t"
12306       $$emit$$"j$cop,u,s  $labl\n\t"
12307       $$emit$$"done:"
12308     }
12309   %}
12310   size(4);
12311   opcode(0x70);
12312   ins_encode %{
12313     Label* l = $labl$$label;
12314     emit_cc(cbuf, $primary, Assembler::parity);
12315     int parity_disp = -1;
12316     if ($cop$$cmpcode == Assembler::notEqual) {
12317       parity_disp = l->loc_pos() - (cbuf.insts_size() + 1);
12318     } else if ($cop$$cmpcode == Assembler::equal) {
12319       parity_disp = 2;
12320     } else {
12321       ShouldNotReachHere();
12322     }
12323     emit_d8(cbuf, parity_disp);
12324     emit_cc(cbuf, $primary, $cop$$cmpcode);
12325     int disp = l->loc_pos() - (cbuf.insts_size() + 1);
12326     emit_d8(cbuf, disp);
12327     assert(-128 <= disp && disp <= 127, "Displacement too large for short jmp");
12328     assert(-128 <= parity_disp && parity_disp <= 127, "Displacement too large for short jmp");
12329   %}
12330   ins_pipe(pipe_jcc);
12331   ins_short_branch(1);
12332 %}
12333 
12334 // ============================================================================
12335 // inlined locking and unlocking
12336 
12337 instruct cmpFastLock(rFlagsReg cr,
12338                      rRegP object, rRegP box, rax_RegI tmp, rRegP scr)
12339 %{
12340   match(Set cr (FastLock object box));
12341   effect(TEMP tmp, TEMP scr);
12342 
12343   ins_cost(300);
12344   format %{ "fastlock $object,$box,$tmp,$scr" %}
12345   ins_encode(Fast_Lock(object, box, tmp, scr));
12346   ins_pipe(pipe_slow);
12347 %}
12348 
12349 instruct cmpFastUnlock(rFlagsReg cr,
12350                        rRegP object, rax_RegP box, rRegP tmp)
12351 %{
12352   match(Set cr (FastUnlock object box));
12353   effect(TEMP tmp);
12354 
12355   ins_cost(300);
12356   format %{ "fastunlock $object, $box, $tmp" %}
12357   ins_encode(Fast_Unlock(object, box, tmp));
12358   ins_pipe(pipe_slow);
12359 %}
12360 
12361 
12362 // ============================================================================
12363 // Safepoint Instructions
12364 instruct safePoint_poll(rFlagsReg cr)
12365 %{
12366   predicate(!Assembler::is_polling_page_far());
12367   match(SafePoint);
12368   effect(KILL cr);
12369 
12370   format %{ "testl  rax, [rip + #offset_to_poll_page]\t"
12371             "# Safepoint: poll for GC" %}
12372   ins_cost(125);
12373   ins_encode %{
12374     AddressLiteral addr(os::get_polling_page(), relocInfo::poll_type);
12375     __ testl(rax, addr);
12376   %}
12377   ins_pipe(ialu_reg_mem);
12378 %}
12379 
12380 instruct safePoint_poll_far(rFlagsReg cr, rRegP poll)
12381 %{
12382   predicate(Assembler::is_polling_page_far());
12383   match(SafePoint poll);
12384   effect(KILL cr, USE poll);
12385 
12386   format %{ "testl  rax, [$poll]\t"
12387             "# Safepoint: poll for GC" %}
12388   ins_cost(125);
12389   ins_encode %{
12390     __ relocate(relocInfo::poll_type);
12391     __ testl(rax, Address($poll$$Register, 0));
12392   %}
12393   ins_pipe(ialu_reg_mem);
12394 %}
12395 
12396 // ============================================================================
12397 // Procedure Call/Return Instructions
12398 // Call Java Static Instruction
12399 // Note: If this code changes, the corresponding ret_addr_offset() and
12400 //       compute_padding() functions will have to be adjusted.
12401 instruct CallStaticJavaDirect(method meth) %{
12402   match(CallStaticJava);
12403   predicate(!((CallStaticJavaNode*) n)->is_method_handle_invoke());
12404   effect(USE meth);
12405 
12406   ins_cost(300);
12407   format %{ "call,static " %}
12408   opcode(0xE8); /* E8 cd */
12409   ins_encode(Java_Static_Call(meth), call_epilog);
12410   ins_pipe(pipe_slow);
12411   ins_alignment(4);
12412 %}
12413 
12414 // Call Java Static Instruction (method handle version)
12415 // Note: If this code changes, the corresponding ret_addr_offset() and
12416 //       compute_padding() functions will have to be adjusted.
12417 instruct CallStaticJavaHandle(method meth, rbp_RegP rbp_mh_SP_save) %{
12418   match(CallStaticJava);
12419   predicate(((CallStaticJavaNode*) n)->is_method_handle_invoke());
12420   effect(USE meth);
12421   // RBP is saved by all callees (for interpreter stack correction).
12422   // We use it here for a similar purpose, in {preserve,restore}_SP.
12423 
12424   ins_cost(300);
12425   format %{ "call,static/MethodHandle " %}
12426   opcode(0xE8); /* E8 cd */
12427   ins_encode(preserve_SP,
12428              Java_Static_Call(meth),
12429              restore_SP,
12430              call_epilog);
12431   ins_pipe(pipe_slow);
12432   ins_alignment(4);
12433 %}
12434 
12435 // Call Java Dynamic Instruction
12436 // Note: If this code changes, the corresponding ret_addr_offset() and
12437 //       compute_padding() functions will have to be adjusted.
12438 instruct CallDynamicJavaDirect(method meth)
12439 %{
12440   match(CallDynamicJava);
12441   effect(USE meth);
12442 
12443   ins_cost(300);
12444   format %{ "movq    rax, #Universe::non_oop_word()\n\t"
12445             "call,dynamic " %}
12446   opcode(0xE8); /* E8 cd */
12447   ins_encode(Java_Dynamic_Call(meth), call_epilog);
12448   ins_pipe(pipe_slow);
12449   ins_alignment(4);
12450 %}
12451 
12452 // Call Runtime Instruction
12453 instruct CallRuntimeDirect(method meth)
12454 %{
12455   match(CallRuntime);
12456   effect(USE meth);
12457 
12458   ins_cost(300);
12459   format %{ "call,runtime " %}
12460   opcode(0xE8); /* E8 cd */
12461   ins_encode(Java_To_Runtime(meth));
12462   ins_pipe(pipe_slow);
12463 %}
12464 
12465 // Call runtime without safepoint
12466 instruct CallLeafDirect(method meth)
12467 %{
12468   match(CallLeaf);
12469   effect(USE meth);
12470 
12471   ins_cost(300);
12472   format %{ "call_leaf,runtime " %}
12473   opcode(0xE8); /* E8 cd */
12474   ins_encode(Java_To_Runtime(meth));
12475   ins_pipe(pipe_slow);
12476 %}
12477 
12478 // Call runtime without safepoint
12479 instruct CallLeafNoFPDirect(method meth)
12480 %{
12481   match(CallLeafNoFP);
12482   effect(USE meth);
12483 
12484   ins_cost(300);
12485   format %{ "call_leaf_nofp,runtime " %}
12486   opcode(0xE8); /* E8 cd */
12487   ins_encode(Java_To_Runtime(meth));
12488   ins_pipe(pipe_slow);
12489 %}
12490 
12491 // Return Instruction
12492 // Remove the return address & jump to it.
12493 // Notice: We always emit a nop after a ret to make sure there is room
12494 // for safepoint patching
12495 instruct Ret()
12496 %{
12497   match(Return);
12498 
12499   format %{ "ret" %}
12500   opcode(0xC3);
12501   ins_encode(OpcP);
12502   ins_pipe(pipe_jmp);
12503 %}
12504 
12505 // Tail Call; Jump from runtime stub to Java code.
12506 // Also known as an 'interprocedural jump'.
12507 // Target of jump will eventually return to caller.
12508 // TailJump below removes the return address.
12509 instruct TailCalljmpInd(no_rbp_RegP jump_target, rbx_RegP method_oop)
12510 %{
12511   match(TailCall jump_target method_oop);
12512 
12513   ins_cost(300);
12514   format %{ "jmp     $jump_target\t# rbx holds method oop" %}
12515   opcode(0xFF, 0x4); /* Opcode FF /4 */
12516   ins_encode(REX_reg(jump_target), OpcP, reg_opc(jump_target));
12517   ins_pipe(pipe_jmp);
12518 %}
12519 
12520 // Tail Jump; remove the return address; jump to target.
12521 // TailCall above leaves the return address around.
12522 instruct tailjmpInd(no_rbp_RegP jump_target, rax_RegP ex_oop)
12523 %{
12524   match(TailJump jump_target ex_oop);
12525 
12526   ins_cost(300);
12527   format %{ "popq    rdx\t# pop return address\n\t"
12528             "jmp     $jump_target" %}
12529   opcode(0xFF, 0x4); /* Opcode FF /4 */
12530   ins_encode(Opcode(0x5a), // popq rdx
12531              REX_reg(jump_target), OpcP, reg_opc(jump_target));
12532   ins_pipe(pipe_jmp);
12533 %}
12534 
12535 // Create exception oop: created by stack-crawling runtime code.
12536 // Created exception is now available to this handler, and is setup
12537 // just prior to jumping to this handler.  No code emitted.
12538 instruct CreateException(rax_RegP ex_oop)
12539 %{
12540   match(Set ex_oop (CreateEx));
12541 
12542   size(0);
12543   // use the following format syntax
12544   format %{ "# exception oop is in rax; no code emitted" %}
12545   ins_encode();
12546   ins_pipe(empty);
12547 %}
12548 
12549 // Rethrow exception:
12550 // The exception oop will come in the first argument position.
12551 // Then JUMP (not call) to the rethrow stub code.
12552 instruct RethrowException()
12553 %{
12554   match(Rethrow);
12555 
12556   // use the following format syntax
12557   format %{ "jmp     rethrow_stub" %}
12558   ins_encode(enc_rethrow);
12559   ins_pipe(pipe_jmp);
12560 %}
12561 
12562 
12563 //----------PEEPHOLE RULES-----------------------------------------------------
12564 // These must follow all instruction definitions as they use the names
12565 // defined in the instructions definitions.
12566 //
12567 // peepmatch ( root_instr_name [preceding_instruction]* );
12568 //
12569 // peepconstraint %{
12570 // (instruction_number.operand_name relational_op instruction_number.operand_name
12571 //  [, ...] );
12572 // // instruction numbers are zero-based using left to right order in peepmatch
12573 //
12574 // peepreplace ( instr_name  ( [instruction_number.operand_name]* ) );
12575 // // provide an instruction_number.operand_name for each operand that appears
12576 // // in the replacement instruction's match rule
12577 //
12578 // ---------VM FLAGS---------------------------------------------------------
12579 //
12580 // All peephole optimizations can be turned off using -XX:-OptoPeephole
12581 //
12582 // Each peephole rule is given an identifying number starting with zero and
12583 // increasing by one in the order seen by the parser.  An individual peephole
12584 // can be enabled, and all others disabled, by using -XX:OptoPeepholeAt=#
12585 // on the command-line.
12586 //
12587 // ---------CURRENT LIMITATIONS----------------------------------------------
12588 //
12589 // Only match adjacent instructions in same basic block
12590 // Only equality constraints
12591 // Only constraints between operands, not (0.dest_reg == RAX_enc)
12592 // Only one replacement instruction
12593 //
12594 // ---------EXAMPLE----------------------------------------------------------
12595 //
12596 // // pertinent parts of existing instructions in architecture description
12597 // instruct movI(rRegI dst, rRegI src)
12598 // %{
12599 //   match(Set dst (CopyI src));
12600 // %}
12601 //
12602 // instruct incI_rReg(rRegI dst, immI1 src, rFlagsReg cr)
12603 // %{
12604 //   match(Set dst (AddI dst src));
12605 //   effect(KILL cr);
12606 // %}
12607 //
12608 // // Change (inc mov) to lea
12609 // peephole %{
12610 //   // increment preceeded by register-register move
12611 //   peepmatch ( incI_rReg movI );
12612 //   // require that the destination register of the increment
12613 //   // match the destination register of the move
12614 //   peepconstraint ( 0.dst == 1.dst );
12615 //   // construct a replacement instruction that sets
12616 //   // the destination to ( move's source register + one )
12617 //   peepreplace ( leaI_rReg_immI( 0.dst 1.src 0.src ) );
12618 // %}
12619 //
12620 
12621 // Implementation no longer uses movX instructions since
12622 // machine-independent system no longer uses CopyX nodes.
12623 //
12624 // peephole
12625 // %{
12626 //   peepmatch (incI_rReg movI);
12627 //   peepconstraint (0.dst == 1.dst);
12628 //   peepreplace (leaI_rReg_immI(0.dst 1.src 0.src));
12629 // %}
12630 
12631 // peephole
12632 // %{
12633 //   peepmatch (decI_rReg movI);
12634 //   peepconstraint (0.dst == 1.dst);
12635 //   peepreplace (leaI_rReg_immI(0.dst 1.src 0.src));
12636 // %}
12637 
12638 // peephole
12639 // %{
12640 //   peepmatch (addI_rReg_imm movI);
12641 //   peepconstraint (0.dst == 1.dst);
12642 //   peepreplace (leaI_rReg_immI(0.dst 1.src 0.src));
12643 // %}
12644 
12645 // peephole
12646 // %{
12647 //   peepmatch (incL_rReg movL);
12648 //   peepconstraint (0.dst == 1.dst);
12649 //   peepreplace (leaL_rReg_immL(0.dst 1.src 0.src));
12650 // %}
12651 
12652 // peephole
12653 // %{
12654 //   peepmatch (decL_rReg movL);
12655 //   peepconstraint (0.dst == 1.dst);
12656 //   peepreplace (leaL_rReg_immL(0.dst 1.src 0.src));
12657 // %}
12658 
12659 // peephole
12660 // %{
12661 //   peepmatch (addL_rReg_imm movL);
12662 //   peepconstraint (0.dst == 1.dst);
12663 //   peepreplace (leaL_rReg_immL(0.dst 1.src 0.src));
12664 // %}
12665 
12666 // peephole
12667 // %{
12668 //   peepmatch (addP_rReg_imm movP);
12669 //   peepconstraint (0.dst == 1.dst);
12670 //   peepreplace (leaP_rReg_imm(0.dst 1.src 0.src));
12671 // %}
12672 
12673 // // Change load of spilled value to only a spill
12674 // instruct storeI(memory mem, rRegI src)
12675 // %{
12676 //   match(Set mem (StoreI mem src));
12677 // %}
12678 //
12679 // instruct loadI(rRegI dst, memory mem)
12680 // %{
12681 //   match(Set dst (LoadI mem));
12682 // %}
12683 //
12684 
12685 peephole
12686 %{
12687   peepmatch (loadI storeI);
12688   peepconstraint (1.src == 0.dst, 1.mem == 0.mem);
12689   peepreplace (storeI(1.mem 1.mem 1.src));
12690 %}
12691 
12692 peephole
12693 %{
12694   peepmatch (loadL storeL);
12695   peepconstraint (1.src == 0.dst, 1.mem == 0.mem);
12696   peepreplace (storeL(1.mem 1.mem 1.src));
12697 %}
12698 
12699 //----------SMARTSPILL RULES---------------------------------------------------
12700 // These must follow all instruction definitions as they use the names
12701 // defined in the instructions definitions.