src/cpu/x86/vm/assembler_x86.hpp

Fri, 13 Mar 2009 11:35:17 -0700

author
twisti
date
Fri, 13 Mar 2009 11:35:17 -0700
changeset 1078
c771b7f43bbf
parent 1077
660978a2a31a
child 1079
c517646eef23
permissions
-rw-r--r--

6378821: bitCount() should use POPC on SPARC processors and AMD+10h
Summary: bitCount() should use POPC on SPARC processors where POPC is implemented directly in hardware.
Reviewed-by: kvn, never

     1 /*
     2  * Copyright 1997-2009 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 class BiasedLockingCounters;
    27 // Contains all the definitions needed for x86 assembly code generation.
    29 // Calling convention
    30 class Argument VALUE_OBJ_CLASS_SPEC {
    31  public:
    32   enum {
    33 #ifdef _LP64
    34 #ifdef _WIN64
    35     n_int_register_parameters_c   = 4, // rcx, rdx, r8, r9 (c_rarg0, c_rarg1, ...)
    36     n_float_register_parameters_c = 4,  // xmm0 - xmm3 (c_farg0, c_farg1, ... )
    37 #else
    38     n_int_register_parameters_c   = 6, // rdi, rsi, rdx, rcx, r8, r9 (c_rarg0, c_rarg1, ...)
    39     n_float_register_parameters_c = 8,  // xmm0 - xmm7 (c_farg0, c_farg1, ... )
    40 #endif // _WIN64
    41     n_int_register_parameters_j   = 6, // j_rarg0, j_rarg1, ...
    42     n_float_register_parameters_j = 8  // j_farg0, j_farg1, ...
    43 #else
    44     n_register_parameters = 0   // 0 registers used to pass arguments
    45 #endif // _LP64
    46   };
    47 };
    50 #ifdef _LP64
    51 // Symbolically name the register arguments used by the c calling convention.
    52 // Windows is different from linux/solaris. So much for standards...
    54 #ifdef _WIN64
    56 REGISTER_DECLARATION(Register, c_rarg0, rcx);
    57 REGISTER_DECLARATION(Register, c_rarg1, rdx);
    58 REGISTER_DECLARATION(Register, c_rarg2, r8);
    59 REGISTER_DECLARATION(Register, c_rarg3, r9);
    61 REGISTER_DECLARATION(XMMRegister, c_farg0, xmm0);
    62 REGISTER_DECLARATION(XMMRegister, c_farg1, xmm1);
    63 REGISTER_DECLARATION(XMMRegister, c_farg2, xmm2);
    64 REGISTER_DECLARATION(XMMRegister, c_farg3, xmm3);
    66 #else
    68 REGISTER_DECLARATION(Register, c_rarg0, rdi);
    69 REGISTER_DECLARATION(Register, c_rarg1, rsi);
    70 REGISTER_DECLARATION(Register, c_rarg2, rdx);
    71 REGISTER_DECLARATION(Register, c_rarg3, rcx);
    72 REGISTER_DECLARATION(Register, c_rarg4, r8);
    73 REGISTER_DECLARATION(Register, c_rarg5, r9);
    75 REGISTER_DECLARATION(XMMRegister, c_farg0, xmm0);
    76 REGISTER_DECLARATION(XMMRegister, c_farg1, xmm1);
    77 REGISTER_DECLARATION(XMMRegister, c_farg2, xmm2);
    78 REGISTER_DECLARATION(XMMRegister, c_farg3, xmm3);
    79 REGISTER_DECLARATION(XMMRegister, c_farg4, xmm4);
    80 REGISTER_DECLARATION(XMMRegister, c_farg5, xmm5);
    81 REGISTER_DECLARATION(XMMRegister, c_farg6, xmm6);
    82 REGISTER_DECLARATION(XMMRegister, c_farg7, xmm7);
    84 #endif // _WIN64
    86 // Symbolically name the register arguments used by the Java calling convention.
    87 // We have control over the convention for java so we can do what we please.
    88 // What pleases us is to offset the java calling convention so that when
    89 // we call a suitable jni method the arguments are lined up and we don't
    90 // have to do little shuffling. A suitable jni method is non-static and a
    91 // small number of arguments (two fewer args on windows)
    92 //
    93 //        |-------------------------------------------------------|
    94 //        | c_rarg0   c_rarg1  c_rarg2 c_rarg3 c_rarg4 c_rarg5    |
    95 //        |-------------------------------------------------------|
    96 //        | rcx       rdx      r8      r9      rdi*    rsi*       | windows (* not a c_rarg)
    97 //        | rdi       rsi      rdx     rcx     r8      r9         | solaris/linux
    98 //        |-------------------------------------------------------|
    99 //        | j_rarg5   j_rarg0  j_rarg1 j_rarg2 j_rarg3 j_rarg4    |
   100 //        |-------------------------------------------------------|
   102 REGISTER_DECLARATION(Register, j_rarg0, c_rarg1);
   103 REGISTER_DECLARATION(Register, j_rarg1, c_rarg2);
   104 REGISTER_DECLARATION(Register, j_rarg2, c_rarg3);
   105 // Windows runs out of register args here
   106 #ifdef _WIN64
   107 REGISTER_DECLARATION(Register, j_rarg3, rdi);
   108 REGISTER_DECLARATION(Register, j_rarg4, rsi);
   109 #else
   110 REGISTER_DECLARATION(Register, j_rarg3, c_rarg4);
   111 REGISTER_DECLARATION(Register, j_rarg4, c_rarg5);
   112 #endif /* _WIN64 */
   113 REGISTER_DECLARATION(Register, j_rarg5, c_rarg0);
   115 REGISTER_DECLARATION(XMMRegister, j_farg0, xmm0);
   116 REGISTER_DECLARATION(XMMRegister, j_farg1, xmm1);
   117 REGISTER_DECLARATION(XMMRegister, j_farg2, xmm2);
   118 REGISTER_DECLARATION(XMMRegister, j_farg3, xmm3);
   119 REGISTER_DECLARATION(XMMRegister, j_farg4, xmm4);
   120 REGISTER_DECLARATION(XMMRegister, j_farg5, xmm5);
   121 REGISTER_DECLARATION(XMMRegister, j_farg6, xmm6);
   122 REGISTER_DECLARATION(XMMRegister, j_farg7, xmm7);
   124 REGISTER_DECLARATION(Register, rscratch1, r10);  // volatile
   125 REGISTER_DECLARATION(Register, rscratch2, r11);  // volatile
   127 REGISTER_DECLARATION(Register, r12_heapbase, r12); // callee-saved
   128 REGISTER_DECLARATION(Register, r15_thread, r15); // callee-saved
   130 #else
   131 // rscratch1 will apear in 32bit code that is dead but of course must compile
   132 // Using noreg ensures if the dead code is incorrectly live and executed it
   133 // will cause an assertion failure
   134 #define rscratch1 noreg
   136 #endif // _LP64
   138 // Address is an abstraction used to represent a memory location
   139 // using any of the amd64 addressing modes with one object.
   140 //
   141 // Note: A register location is represented via a Register, not
   142 //       via an address for efficiency & simplicity reasons.
   144 class ArrayAddress;
   146 class Address VALUE_OBJ_CLASS_SPEC {
   147  public:
   148   enum ScaleFactor {
   149     no_scale = -1,
   150     times_1  =  0,
   151     times_2  =  1,
   152     times_4  =  2,
   153     times_8  =  3,
   154     times_ptr = LP64_ONLY(times_8) NOT_LP64(times_4)
   155   };
   156   static ScaleFactor times(int size) {
   157     assert(size >= 1 && size <= 8 && is_power_of_2(size), "bad scale size");
   158     if (size == 8)  return times_8;
   159     if (size == 4)  return times_4;
   160     if (size == 2)  return times_2;
   161     return times_1;
   162   }
   163   static int scale_size(ScaleFactor scale) {
   164     assert(scale != no_scale, "");
   165     assert(((1 << (int)times_1) == 1 &&
   166             (1 << (int)times_2) == 2 &&
   167             (1 << (int)times_4) == 4 &&
   168             (1 << (int)times_8) == 8), "");
   169     return (1 << (int)scale);
   170   }
   172  private:
   173   Register         _base;
   174   Register         _index;
   175   ScaleFactor      _scale;
   176   int              _disp;
   177   RelocationHolder _rspec;
   179   // Easily misused constructors make them private
   180   // %%% can we make these go away?
   181   NOT_LP64(Address(address loc, RelocationHolder spec);)
   182   Address(int disp, address loc, relocInfo::relocType rtype);
   183   Address(int disp, address loc, RelocationHolder spec);
   185  public:
   187  int disp() { return _disp; }
   188   // creation
   189   Address()
   190     : _base(noreg),
   191       _index(noreg),
   192       _scale(no_scale),
   193       _disp(0) {
   194   }
   196   // No default displacement otherwise Register can be implicitly
   197   // converted to 0(Register) which is quite a different animal.
   199   Address(Register base, int disp)
   200     : _base(base),
   201       _index(noreg),
   202       _scale(no_scale),
   203       _disp(disp) {
   204   }
   206   Address(Register base, Register index, ScaleFactor scale, int disp = 0)
   207     : _base (base),
   208       _index(index),
   209       _scale(scale),
   210       _disp (disp) {
   211     assert(!index->is_valid() == (scale == Address::no_scale),
   212            "inconsistent address");
   213   }
   215   Address(Register base, RegisterConstant index, ScaleFactor scale = times_1, int disp = 0)
   216     : _base (base),
   217       _index(index.register_or_noreg()),
   218       _scale(scale),
   219       _disp (disp + (index.constant_or_zero() * scale_size(scale))) {
   220     if (!index.is_register())  scale = Address::no_scale;
   221     assert(!_index->is_valid() == (scale == Address::no_scale),
   222            "inconsistent address");
   223   }
   225   Address plus_disp(int disp) const {
   226     Address a = (*this);
   227     a._disp += disp;
   228     return a;
   229   }
   231   // The following two overloads are used in connection with the
   232   // ByteSize type (see sizes.hpp).  They simplify the use of
   233   // ByteSize'd arguments in assembly code. Note that their equivalent
   234   // for the optimized build are the member functions with int disp
   235   // argument since ByteSize is mapped to an int type in that case.
   236   //
   237   // Note: DO NOT introduce similar overloaded functions for WordSize
   238   // arguments as in the optimized mode, both ByteSize and WordSize
   239   // are mapped to the same type and thus the compiler cannot make a
   240   // distinction anymore (=> compiler errors).
   242 #ifdef ASSERT
   243   Address(Register base, ByteSize disp)
   244     : _base(base),
   245       _index(noreg),
   246       _scale(no_scale),
   247       _disp(in_bytes(disp)) {
   248   }
   250   Address(Register base, Register index, ScaleFactor scale, ByteSize disp)
   251     : _base(base),
   252       _index(index),
   253       _scale(scale),
   254       _disp(in_bytes(disp)) {
   255     assert(!index->is_valid() == (scale == Address::no_scale),
   256            "inconsistent address");
   257   }
   259   Address(Register base, RegisterConstant index, ScaleFactor scale, ByteSize disp)
   260     : _base (base),
   261       _index(index.register_or_noreg()),
   262       _scale(scale),
   263       _disp (in_bytes(disp) + (index.constant_or_zero() * scale_size(scale))) {
   264     if (!index.is_register())  scale = Address::no_scale;
   265     assert(!_index->is_valid() == (scale == Address::no_scale),
   266            "inconsistent address");
   267   }
   269 #endif // ASSERT
   271   // accessors
   272   bool        uses(Register reg) const { return _base == reg || _index == reg; }
   273   Register    base()             const { return _base;  }
   274   Register    index()            const { return _index; }
   275   ScaleFactor scale()            const { return _scale; }
   276   int         disp()             const { return _disp;  }
   278   // Convert the raw encoding form into the form expected by the constructor for
   279   // Address.  An index of 4 (rsp) corresponds to having no index, so convert
   280   // that to noreg for the Address constructor.
   281   static Address make_raw(int base, int index, int scale, int disp, bool disp_is_oop);
   283   static Address make_array(ArrayAddress);
   285  private:
   286   bool base_needs_rex() const {
   287     return _base != noreg && _base->encoding() >= 8;
   288   }
   290   bool index_needs_rex() const {
   291     return _index != noreg &&_index->encoding() >= 8;
   292   }
   294   relocInfo::relocType reloc() const { return _rspec.type(); }
   296   friend class Assembler;
   297   friend class MacroAssembler;
   298   friend class LIR_Assembler; // base/index/scale/disp
   299 };
   301 //
   302 // AddressLiteral has been split out from Address because operands of this type
   303 // need to be treated specially on 32bit vs. 64bit platforms. By splitting it out
   304 // the few instructions that need to deal with address literals are unique and the
   305 // MacroAssembler does not have to implement every instruction in the Assembler
   306 // in order to search for address literals that may need special handling depending
   307 // on the instruction and the platform. As small step on the way to merging i486/amd64
   308 // directories.
   309 //
   310 class AddressLiteral VALUE_OBJ_CLASS_SPEC {
   311   friend class ArrayAddress;
   312   RelocationHolder _rspec;
   313   // Typically we use AddressLiterals we want to use their rval
   314   // However in some situations we want the lval (effect address) of the item.
   315   // We provide a special factory for making those lvals.
   316   bool _is_lval;
   318   // If the target is far we'll need to load the ea of this to
   319   // a register to reach it. Otherwise if near we can do rip
   320   // relative addressing.
   322   address          _target;
   324  protected:
   325   // creation
   326   AddressLiteral()
   327     : _is_lval(false),
   328       _target(NULL)
   329   {}
   331   public:
   334   AddressLiteral(address target, relocInfo::relocType rtype);
   336   AddressLiteral(address target, RelocationHolder const& rspec)
   337     : _rspec(rspec),
   338       _is_lval(false),
   339       _target(target)
   340   {}
   342   AddressLiteral addr() {
   343     AddressLiteral ret = *this;
   344     ret._is_lval = true;
   345     return ret;
   346   }
   349  private:
   351   address target() { return _target; }
   352   bool is_lval() { return _is_lval; }
   354   relocInfo::relocType reloc() const { return _rspec.type(); }
   355   const RelocationHolder& rspec() const { return _rspec; }
   357   friend class Assembler;
   358   friend class MacroAssembler;
   359   friend class Address;
   360   friend class LIR_Assembler;
   361 };
   363 // Convience classes
   364 class RuntimeAddress: public AddressLiteral {
   366   public:
   368   RuntimeAddress(address target) : AddressLiteral(target, relocInfo::runtime_call_type) {}
   370 };
   372 class OopAddress: public AddressLiteral {
   374   public:
   376   OopAddress(address target) : AddressLiteral(target, relocInfo::oop_type){}
   378 };
   380 class ExternalAddress: public AddressLiteral {
   382   public:
   384   ExternalAddress(address target) : AddressLiteral(target, relocInfo::external_word_type){}
   386 };
   388 class InternalAddress: public AddressLiteral {
   390   public:
   392   InternalAddress(address target) : AddressLiteral(target, relocInfo::internal_word_type) {}
   394 };
   396 // x86 can do array addressing as a single operation since disp can be an absolute
   397 // address amd64 can't. We create a class that expresses the concept but does extra
   398 // magic on amd64 to get the final result
   400 class ArrayAddress VALUE_OBJ_CLASS_SPEC {
   401   private:
   403   AddressLiteral _base;
   404   Address        _index;
   406   public:
   408   ArrayAddress() {};
   409   ArrayAddress(AddressLiteral base, Address index): _base(base), _index(index) {};
   410   AddressLiteral base() { return _base; }
   411   Address index() { return _index; }
   413 };
   415 const int FPUStateSizeInWords = NOT_LP64(27) LP64_ONLY( 512 / wordSize);
   417 // The Intel x86/Amd64 Assembler: Pure assembler doing NO optimizations on the instruction
   418 // level (e.g. mov rax, 0 is not translated into xor rax, rax!); i.e., what you write
   419 // is what you get. The Assembler is generating code into a CodeBuffer.
   421 class Assembler : public AbstractAssembler  {
   422   friend class AbstractAssembler; // for the non-virtual hack
   423   friend class LIR_Assembler; // as_Address()
   424   friend class StubGenerator;
   426  public:
   427   enum Condition {                     // The x86 condition codes used for conditional jumps/moves.
   428     zero          = 0x4,
   429     notZero       = 0x5,
   430     equal         = 0x4,
   431     notEqual      = 0x5,
   432     less          = 0xc,
   433     lessEqual     = 0xe,
   434     greater       = 0xf,
   435     greaterEqual  = 0xd,
   436     below         = 0x2,
   437     belowEqual    = 0x6,
   438     above         = 0x7,
   439     aboveEqual    = 0x3,
   440     overflow      = 0x0,
   441     noOverflow    = 0x1,
   442     carrySet      = 0x2,
   443     carryClear    = 0x3,
   444     negative      = 0x8,
   445     positive      = 0x9,
   446     parity        = 0xa,
   447     noParity      = 0xb
   448   };
   450   enum Prefix {
   451     // segment overrides
   452     CS_segment = 0x2e,
   453     SS_segment = 0x36,
   454     DS_segment = 0x3e,
   455     ES_segment = 0x26,
   456     FS_segment = 0x64,
   457     GS_segment = 0x65,
   459     REX        = 0x40,
   461     REX_B      = 0x41,
   462     REX_X      = 0x42,
   463     REX_XB     = 0x43,
   464     REX_R      = 0x44,
   465     REX_RB     = 0x45,
   466     REX_RX     = 0x46,
   467     REX_RXB    = 0x47,
   469     REX_W      = 0x48,
   471     REX_WB     = 0x49,
   472     REX_WX     = 0x4A,
   473     REX_WXB    = 0x4B,
   474     REX_WR     = 0x4C,
   475     REX_WRB    = 0x4D,
   476     REX_WRX    = 0x4E,
   477     REX_WRXB   = 0x4F
   478   };
   480   enum WhichOperand {
   481     // input to locate_operand, and format code for relocations
   482     imm_operand  = 0,            // embedded 32-bit|64-bit immediate operand
   483     disp32_operand = 1,          // embedded 32-bit displacement or address
   484     call32_operand = 2,          // embedded 32-bit self-relative displacement
   485 #ifndef _LP64
   486     _WhichOperand_limit = 3
   487 #else
   488      narrow_oop_operand = 3,     // embedded 32-bit immediate narrow oop
   489     _WhichOperand_limit = 4
   490 #endif
   491   };
   495   // NOTE: The general philopsophy of the declarations here is that 64bit versions
   496   // of instructions are freely declared without the need for wrapping them an ifdef.
   497   // (Some dangerous instructions are ifdef's out of inappropriate jvm's.)
   498   // In the .cpp file the implementations are wrapped so that they are dropped out
   499   // of the resulting jvm. This is done mostly to keep the footprint of KERNEL
   500   // to the size it was prior to merging up the 32bit and 64bit assemblers.
   501   //
   502   // This does mean you'll get a linker/runtime error if you use a 64bit only instruction
   503   // in a 32bit vm. This is somewhat unfortunate but keeps the ifdef noise down.
   505 private:
   508   // 64bit prefixes
   509   int prefix_and_encode(int reg_enc, bool byteinst = false);
   510   int prefixq_and_encode(int reg_enc);
   512   int prefix_and_encode(int dst_enc, int src_enc, bool byteinst = false);
   513   int prefixq_and_encode(int dst_enc, int src_enc);
   515   void prefix(Register reg);
   516   void prefix(Address adr);
   517   void prefixq(Address adr);
   519   void prefix(Address adr, Register reg,  bool byteinst = false);
   520   void prefixq(Address adr, Register reg);
   522   void prefix(Address adr, XMMRegister reg);
   524   void prefetch_prefix(Address src);
   526   // Helper functions for groups of instructions
   527   void emit_arith_b(int op1, int op2, Register dst, int imm8);
   529   void emit_arith(int op1, int op2, Register dst, int32_t imm32);
   530   // only 32bit??
   531   void emit_arith(int op1, int op2, Register dst, jobject obj);
   532   void emit_arith(int op1, int op2, Register dst, Register src);
   534   void emit_operand(Register reg,
   535                     Register base, Register index, Address::ScaleFactor scale,
   536                     int disp,
   537                     RelocationHolder const& rspec,
   538                     int rip_relative_correction = 0);
   540   void emit_operand(Register reg, Address adr, int rip_relative_correction = 0);
   542   // operands that only take the original 32bit registers
   543   void emit_operand32(Register reg, Address adr);
   545   void emit_operand(XMMRegister reg,
   546                     Register base, Register index, Address::ScaleFactor scale,
   547                     int disp,
   548                     RelocationHolder const& rspec);
   550   void emit_operand(XMMRegister reg, Address adr);
   552   void emit_operand(MMXRegister reg, Address adr);
   554   // workaround gcc (3.2.1-7) bug
   555   void emit_operand(Address adr, MMXRegister reg);
   558   // Immediate-to-memory forms
   559   void emit_arith_operand(int op1, Register rm, Address adr, int32_t imm32);
   561   void emit_farith(int b1, int b2, int i);
   564  protected:
   565   #ifdef ASSERT
   566   void check_relocation(RelocationHolder const& rspec, int format);
   567   #endif
   569   inline void emit_long64(jlong x);
   571   void emit_data(jint data, relocInfo::relocType    rtype, int format);
   572   void emit_data(jint data, RelocationHolder const& rspec, int format);
   573   void emit_data64(jlong data, relocInfo::relocType rtype, int format = 0);
   574   void emit_data64(jlong data, RelocationHolder const& rspec, int format = 0);
   577   bool reachable(AddressLiteral adr) NOT_LP64({ return true;});
   579   // These are all easily abused and hence protected
   581   // 32BIT ONLY SECTION
   582 #ifndef _LP64
   583   // Make these disappear in 64bit mode since they would never be correct
   584   void cmp_literal32(Register src1, int32_t imm32, RelocationHolder const& rspec);   // 32BIT ONLY
   585   void cmp_literal32(Address src1, int32_t imm32, RelocationHolder const& rspec);    // 32BIT ONLY
   587   void mov_literal32(Register dst, int32_t imm32, RelocationHolder const& rspec);    // 32BIT ONLY
   588   void mov_literal32(Address dst, int32_t imm32, RelocationHolder const& rspec);     // 32BIT ONLY
   590   void push_literal32(int32_t imm32, RelocationHolder const& rspec);                 // 32BIT ONLY
   591 #else
   592   // 64BIT ONLY SECTION
   593   void mov_literal64(Register dst, intptr_t imm64, RelocationHolder const& rspec);   // 64BIT ONLY
   595   void cmp_narrow_oop(Register src1, int32_t imm32, RelocationHolder const& rspec);
   596   void cmp_narrow_oop(Address src1, int32_t imm32, RelocationHolder const& rspec);
   598   void mov_narrow_oop(Register dst, int32_t imm32, RelocationHolder const& rspec);
   599   void mov_narrow_oop(Address dst, int32_t imm32, RelocationHolder const& rspec);
   600 #endif // _LP64
   602   // These are unique in that we are ensured by the caller that the 32bit
   603   // relative in these instructions will always be able to reach the potentially
   604   // 64bit address described by entry. Since they can take a 64bit address they
   605   // don't have the 32 suffix like the other instructions in this class.
   607   void call_literal(address entry, RelocationHolder const& rspec);
   608   void jmp_literal(address entry, RelocationHolder const& rspec);
   610   // Avoid using directly section
   611   // Instructions in this section are actually usable by anyone without danger
   612   // of failure but have performance issues that are addressed my enhanced
   613   // instructions which will do the proper thing base on the particular cpu.
   614   // We protect them because we don't trust you...
   616   // Don't use next inc() and dec() methods directly. INC & DEC instructions
   617   // could cause a partial flag stall since they don't set CF flag.
   618   // Use MacroAssembler::decrement() & MacroAssembler::increment() methods
   619   // which call inc() & dec() or add() & sub() in accordance with
   620   // the product flag UseIncDec value.
   622   void decl(Register dst);
   623   void decl(Address dst);
   624   void decq(Register dst);
   625   void decq(Address dst);
   627   void incl(Register dst);
   628   void incl(Address dst);
   629   void incq(Register dst);
   630   void incq(Address dst);
   632   // New cpus require use of movsd and movss to avoid partial register stall
   633   // when loading from memory. But for old Opteron use movlpd instead of movsd.
   634   // The selection is done in MacroAssembler::movdbl() and movflt().
   636   // Move Scalar Single-Precision Floating-Point Values
   637   void movss(XMMRegister dst, Address src);
   638   void movss(XMMRegister dst, XMMRegister src);
   639   void movss(Address dst, XMMRegister src);
   641   // Move Scalar Double-Precision Floating-Point Values
   642   void movsd(XMMRegister dst, Address src);
   643   void movsd(XMMRegister dst, XMMRegister src);
   644   void movsd(Address dst, XMMRegister src);
   645   void movlpd(XMMRegister dst, Address src);
   647   // New cpus require use of movaps and movapd to avoid partial register stall
   648   // when moving between registers.
   649   void movaps(XMMRegister dst, XMMRegister src);
   650   void movapd(XMMRegister dst, XMMRegister src);
   652   // End avoid using directly
   655   // Instruction prefixes
   656   void prefix(Prefix p);
   658   public:
   660   // Creation
   661   Assembler(CodeBuffer* code) : AbstractAssembler(code) {}
   663   // Decoding
   664   static address locate_operand(address inst, WhichOperand which);
   665   static address locate_next_instruction(address inst);
   667   // Utilities
   669 #ifdef _LP64
   670  static bool is_simm(int64_t x, int nbits) { return -( CONST64(1) << (nbits-1) )  <= x   &&   x  <  ( CONST64(1) << (nbits-1) ); }
   671  static bool is_simm32(int64_t x) { return x == (int64_t)(int32_t)x; }
   672 #else
   673  static bool is_simm(int32_t x, int nbits) { return -( 1 << (nbits-1) )  <= x   &&   x  <  ( 1 << (nbits-1) ); }
   674  static bool is_simm32(int32_t x) { return true; }
   675 #endif // LP64
   677   // Generic instructions
   678   // Does 32bit or 64bit as needed for the platform. In some sense these
   679   // belong in macro assembler but there is no need for both varieties to exist
   681   void lea(Register dst, Address src);
   683   void mov(Register dst, Register src);
   685   void pusha();
   686   void popa();
   688   void pushf();
   689   void popf();
   691   void push(int32_t imm32);
   693   void push(Register src);
   695   void pop(Register dst);
   697   // These are dummies to prevent surprise implicit conversions to Register
   698   void push(void* v);
   699   void pop(void* v);
   702   // These do register sized moves/scans
   703   void rep_mov();
   704   void rep_set();
   705   void repne_scan();
   706 #ifdef _LP64
   707   void repne_scanl();
   708 #endif
   710   // Vanilla instructions in lexical order
   712   void adcl(Register dst, int32_t imm32);
   713   void adcl(Register dst, Address src);
   714   void adcl(Register dst, Register src);
   716   void adcq(Register dst, int32_t imm32);
   717   void adcq(Register dst, Address src);
   718   void adcq(Register dst, Register src);
   721   void addl(Address dst, int32_t imm32);
   722   void addl(Address dst, Register src);
   723   void addl(Register dst, int32_t imm32);
   724   void addl(Register dst, Address src);
   725   void addl(Register dst, Register src);
   727   void addq(Address dst, int32_t imm32);
   728   void addq(Address dst, Register src);
   729   void addq(Register dst, int32_t imm32);
   730   void addq(Register dst, Address src);
   731   void addq(Register dst, Register src);
   734   void addr_nop_4();
   735   void addr_nop_5();
   736   void addr_nop_7();
   737   void addr_nop_8();
   739   // Add Scalar Double-Precision Floating-Point Values
   740   void addsd(XMMRegister dst, Address src);
   741   void addsd(XMMRegister dst, XMMRegister src);
   743   // Add Scalar Single-Precision Floating-Point Values
   744   void addss(XMMRegister dst, Address src);
   745   void addss(XMMRegister dst, XMMRegister src);
   747   void andl(Register dst, int32_t imm32);
   748   void andl(Register dst, Address src);
   749   void andl(Register dst, Register src);
   751   void andq(Register dst, int32_t imm32);
   752   void andq(Register dst, Address src);
   753   void andq(Register dst, Register src);
   756   // Bitwise Logical AND of Packed Double-Precision Floating-Point Values
   757   void andpd(XMMRegister dst, Address src);
   758   void andpd(XMMRegister dst, XMMRegister src);
   760   void bswapl(Register reg);
   762   void bswapq(Register reg);
   764   void call(Label& L, relocInfo::relocType rtype);
   765   void call(Register reg);  // push pc; pc <- reg
   766   void call(Address adr);   // push pc; pc <- adr
   768   void cdql();
   770   void cdqq();
   772   void cld() { emit_byte(0xfc); }
   774   void clflush(Address adr);
   776   void cmovl(Condition cc, Register dst, Register src);
   777   void cmovl(Condition cc, Register dst, Address src);
   779   void cmovq(Condition cc, Register dst, Register src);
   780   void cmovq(Condition cc, Register dst, Address src);
   783   void cmpb(Address dst, int imm8);
   785   void cmpl(Address dst, int32_t imm32);
   787   void cmpl(Register dst, int32_t imm32);
   788   void cmpl(Register dst, Register src);
   789   void cmpl(Register dst, Address src);
   791   void cmpq(Address dst, int32_t imm32);
   792   void cmpq(Address dst, Register src);
   794   void cmpq(Register dst, int32_t imm32);
   795   void cmpq(Register dst, Register src);
   796   void cmpq(Register dst, Address src);
   798   // these are dummies used to catch attempting to convert NULL to Register
   799   void cmpl(Register dst, void* junk); // dummy
   800   void cmpq(Register dst, void* junk); // dummy
   802   void cmpw(Address dst, int imm16);
   804   void cmpxchg8 (Address adr);
   806   void cmpxchgl(Register reg, Address adr);
   808   void cmpxchgq(Register reg, Address adr);
   810   // Ordered Compare Scalar Double-Precision Floating-Point Values and set EFLAGS
   811   void comisd(XMMRegister dst, Address src);
   813   // Ordered Compare Scalar Single-Precision Floating-Point Values and set EFLAGS
   814   void comiss(XMMRegister dst, Address src);
   816   // Identify processor type and features
   817   void cpuid() {
   818     emit_byte(0x0F);
   819     emit_byte(0xA2);
   820   }
   822   // Convert Scalar Double-Precision Floating-Point Value to Scalar Single-Precision Floating-Point Value
   823   void cvtsd2ss(XMMRegister dst, XMMRegister src);
   825   // Convert Doubleword Integer to Scalar Double-Precision Floating-Point Value
   826   void cvtsi2sdl(XMMRegister dst, Register src);
   827   void cvtsi2sdq(XMMRegister dst, Register src);
   829   // Convert Doubleword Integer to Scalar Single-Precision Floating-Point Value
   830   void cvtsi2ssl(XMMRegister dst, Register src);
   831   void cvtsi2ssq(XMMRegister dst, Register src);
   833   // Convert Packed Signed Doubleword Integers to Packed Double-Precision Floating-Point Value
   834   void cvtdq2pd(XMMRegister dst, XMMRegister src);
   836   // Convert Packed Signed Doubleword Integers to Packed Single-Precision Floating-Point Value
   837   void cvtdq2ps(XMMRegister dst, XMMRegister src);
   839   // Convert Scalar Single-Precision Floating-Point Value to Scalar Double-Precision Floating-Point Value
   840   void cvtss2sd(XMMRegister dst, XMMRegister src);
   842   // Convert with Truncation Scalar Double-Precision Floating-Point Value to Doubleword Integer
   843   void cvttsd2sil(Register dst, Address src);
   844   void cvttsd2sil(Register dst, XMMRegister src);
   845   void cvttsd2siq(Register dst, XMMRegister src);
   847   // Convert with Truncation Scalar Single-Precision Floating-Point Value to Doubleword Integer
   848   void cvttss2sil(Register dst, XMMRegister src);
   849   void cvttss2siq(Register dst, XMMRegister src);
   851   // Divide Scalar Double-Precision Floating-Point Values
   852   void divsd(XMMRegister dst, Address src);
   853   void divsd(XMMRegister dst, XMMRegister src);
   855   // Divide Scalar Single-Precision Floating-Point Values
   856   void divss(XMMRegister dst, Address src);
   857   void divss(XMMRegister dst, XMMRegister src);
   859   void emms();
   861   void fabs();
   863   void fadd(int i);
   865   void fadd_d(Address src);
   866   void fadd_s(Address src);
   868   // "Alternate" versions of x87 instructions place result down in FPU
   869   // stack instead of on TOS
   871   void fadda(int i); // "alternate" fadd
   872   void faddp(int i = 1);
   874   void fchs();
   876   void fcom(int i);
   878   void fcomp(int i = 1);
   879   void fcomp_d(Address src);
   880   void fcomp_s(Address src);
   882   void fcompp();
   884   void fcos();
   886   void fdecstp();
   888   void fdiv(int i);
   889   void fdiv_d(Address src);
   890   void fdivr_s(Address src);
   891   void fdiva(int i);  // "alternate" fdiv
   892   void fdivp(int i = 1);
   894   void fdivr(int i);
   895   void fdivr_d(Address src);
   896   void fdiv_s(Address src);
   898   void fdivra(int i); // "alternate" reversed fdiv
   900   void fdivrp(int i = 1);
   902   void ffree(int i = 0);
   904   void fild_d(Address adr);
   905   void fild_s(Address adr);
   907   void fincstp();
   909   void finit();
   911   void fist_s (Address adr);
   912   void fistp_d(Address adr);
   913   void fistp_s(Address adr);
   915   void fld1();
   917   void fld_d(Address adr);
   918   void fld_s(Address adr);
   919   void fld_s(int index);
   920   void fld_x(Address adr);  // extended-precision (80-bit) format
   922   void fldcw(Address src);
   924   void fldenv(Address src);
   926   void fldlg2();
   928   void fldln2();
   930   void fldz();
   932   void flog();
   933   void flog10();
   935   void fmul(int i);
   937   void fmul_d(Address src);
   938   void fmul_s(Address src);
   940   void fmula(int i);  // "alternate" fmul
   942   void fmulp(int i = 1);
   944   void fnsave(Address dst);
   946   void fnstcw(Address src);
   948   void fnstsw_ax();
   950   void fprem();
   951   void fprem1();
   953   void frstor(Address src);
   955   void fsin();
   957   void fsqrt();
   959   void fst_d(Address adr);
   960   void fst_s(Address adr);
   962   void fstp_d(Address adr);
   963   void fstp_d(int index);
   964   void fstp_s(Address adr);
   965   void fstp_x(Address adr); // extended-precision (80-bit) format
   967   void fsub(int i);
   968   void fsub_d(Address src);
   969   void fsub_s(Address src);
   971   void fsuba(int i);  // "alternate" fsub
   973   void fsubp(int i = 1);
   975   void fsubr(int i);
   976   void fsubr_d(Address src);
   977   void fsubr_s(Address src);
   979   void fsubra(int i); // "alternate" reversed fsub
   981   void fsubrp(int i = 1);
   983   void ftan();
   985   void ftst();
   987   void fucomi(int i = 1);
   988   void fucomip(int i = 1);
   990   void fwait();
   992   void fxch(int i = 1);
   994   void fxrstor(Address src);
   996   void fxsave(Address dst);
   998   void fyl2x();
  1000   void hlt();
  1002   void idivl(Register src);
  1004   void idivq(Register src);
  1006   void imull(Register dst, Register src);
  1007   void imull(Register dst, Register src, int value);
  1009   void imulq(Register dst, Register src);
  1010   void imulq(Register dst, Register src, int value);
  1013   // jcc is the generic conditional branch generator to run-
  1014   // time routines, jcc is used for branches to labels. jcc
  1015   // takes a branch opcode (cc) and a label (L) and generates
  1016   // either a backward branch or a forward branch and links it
  1017   // to the label fixup chain. Usage:
  1018   //
  1019   // Label L;      // unbound label
  1020   // jcc(cc, L);   // forward branch to unbound label
  1021   // bind(L);      // bind label to the current pc
  1022   // jcc(cc, L);   // backward branch to bound label
  1023   // bind(L);      // illegal: a label may be bound only once
  1024   //
  1025   // Note: The same Label can be used for forward and backward branches
  1026   // but it may be bound only once.
  1028   void jcc(Condition cc, Label& L,
  1029            relocInfo::relocType rtype = relocInfo::none);
  1031   // Conditional jump to a 8-bit offset to L.
  1032   // WARNING: be very careful using this for forward jumps.  If the label is
  1033   // not bound within an 8-bit offset of this instruction, a run-time error
  1034   // will occur.
  1035   void jccb(Condition cc, Label& L);
  1037   void jmp(Address entry);    // pc <- entry
  1039   // Label operations & relative jumps (PPUM Appendix D)
  1040   void jmp(Label& L, relocInfo::relocType rtype = relocInfo::none);   // unconditional jump to L
  1042   void jmp(Register entry); // pc <- entry
  1044   // Unconditional 8-bit offset jump to L.
  1045   // WARNING: be very careful using this for forward jumps.  If the label is
  1046   // not bound within an 8-bit offset of this instruction, a run-time error
  1047   // will occur.
  1048   void jmpb(Label& L);
  1050   void ldmxcsr( Address src );
  1052   void leal(Register dst, Address src);
  1054   void leaq(Register dst, Address src);
  1056   void lfence() {
  1057     emit_byte(0x0F);
  1058     emit_byte(0xAE);
  1059     emit_byte(0xE8);
  1062   void lock();
  1064   enum Membar_mask_bits {
  1065     StoreStore = 1 << 3,
  1066     LoadStore  = 1 << 2,
  1067     StoreLoad  = 1 << 1,
  1068     LoadLoad   = 1 << 0
  1069   };
  1071   // Serializes memory.
  1072   void membar(Membar_mask_bits order_constraint) {
  1073     // We only have to handle StoreLoad and LoadLoad
  1074     if (order_constraint & StoreLoad) {
  1075       // MFENCE subsumes LFENCE
  1076       mfence();
  1077     } /* [jk] not needed currently: else if (order_constraint & LoadLoad) {
  1078          lfence();
  1079     } */
  1082   void mfence();
  1084   // Moves
  1086   void mov64(Register dst, int64_t imm64);
  1088   void movb(Address dst, Register src);
  1089   void movb(Address dst, int imm8);
  1090   void movb(Register dst, Address src);
  1092   void movdl(XMMRegister dst, Register src);
  1093   void movdl(Register dst, XMMRegister src);
  1095   // Move Double Quadword
  1096   void movdq(XMMRegister dst, Register src);
  1097   void movdq(Register dst, XMMRegister src);
  1099   // Move Aligned Double Quadword
  1100   void movdqa(Address     dst, XMMRegister src);
  1101   void movdqa(XMMRegister dst, Address src);
  1102   void movdqa(XMMRegister dst, XMMRegister src);
  1104   // Move Unaligned Double Quadword
  1105   void movdqu(Address     dst, XMMRegister src);
  1106   void movdqu(XMMRegister dst, Address src);
  1107   void movdqu(XMMRegister dst, XMMRegister src);
  1109   void movl(Register dst, int32_t imm32);
  1110   void movl(Address dst, int32_t imm32);
  1111   void movl(Register dst, Register src);
  1112   void movl(Register dst, Address src);
  1113   void movl(Address dst, Register src);
  1115   // These dummies prevent using movl from converting a zero (like NULL) into Register
  1116   // by giving the compiler two choices it can't resolve
  1118   void movl(Address  dst, void* junk);
  1119   void movl(Register dst, void* junk);
  1121 #ifdef _LP64
  1122   void movq(Register dst, Register src);
  1123   void movq(Register dst, Address src);
  1124   void movq(Address dst, Register src);
  1125 #endif
  1127   void movq(Address     dst, MMXRegister src );
  1128   void movq(MMXRegister dst, Address src );
  1130 #ifdef _LP64
  1131   // These dummies prevent using movq from converting a zero (like NULL) into Register
  1132   // by giving the compiler two choices it can't resolve
  1134   void movq(Address  dst, void* dummy);
  1135   void movq(Register dst, void* dummy);
  1136 #endif
  1138   // Move Quadword
  1139   void movq(Address     dst, XMMRegister src);
  1140   void movq(XMMRegister dst, Address src);
  1142   void movsbl(Register dst, Address src);
  1143   void movsbl(Register dst, Register src);
  1145 #ifdef _LP64
  1146   void movsbq(Register dst, Address src);
  1147   void movsbq(Register dst, Register src);
  1149   // Move signed 32bit immediate to 64bit extending sign
  1150   void movslq(Address dst, int32_t imm64);
  1151   void movslq(Register dst, int32_t imm64);
  1153   void movslq(Register dst, Address src);
  1154   void movslq(Register dst, Register src);
  1155   void movslq(Register dst, void* src); // Dummy declaration to cause NULL to be ambiguous
  1156 #endif
  1158   void movswl(Register dst, Address src);
  1159   void movswl(Register dst, Register src);
  1161 #ifdef _LP64
  1162   void movswq(Register dst, Address src);
  1163   void movswq(Register dst, Register src);
  1164 #endif
  1166   void movw(Address dst, int imm16);
  1167   void movw(Register dst, Address src);
  1168   void movw(Address dst, Register src);
  1170   void movzbl(Register dst, Address src);
  1171   void movzbl(Register dst, Register src);
  1173 #ifdef _LP64
  1174   void movzbq(Register dst, Address src);
  1175   void movzbq(Register dst, Register src);
  1176 #endif
  1178   void movzwl(Register dst, Address src);
  1179   void movzwl(Register dst, Register src);
  1181 #ifdef _LP64
  1182   void movzwq(Register dst, Address src);
  1183   void movzwq(Register dst, Register src);
  1184 #endif
  1186   void mull(Address src);
  1187   void mull(Register src);
  1189   // Multiply Scalar Double-Precision Floating-Point Values
  1190   void mulsd(XMMRegister dst, Address src);
  1191   void mulsd(XMMRegister dst, XMMRegister src);
  1193   // Multiply Scalar Single-Precision Floating-Point Values
  1194   void mulss(XMMRegister dst, Address src);
  1195   void mulss(XMMRegister dst, XMMRegister src);
  1197   void negl(Register dst);
  1199 #ifdef _LP64
  1200   void negq(Register dst);
  1201 #endif
  1203   void nop(int i = 1);
  1205   void notl(Register dst);
  1207 #ifdef _LP64
  1208   void notq(Register dst);
  1209 #endif
  1211   void orl(Address dst, int32_t imm32);
  1212   void orl(Register dst, int32_t imm32);
  1213   void orl(Register dst, Address src);
  1214   void orl(Register dst, Register src);
  1216   void orq(Address dst, int32_t imm32);
  1217   void orq(Register dst, int32_t imm32);
  1218   void orq(Register dst, Address src);
  1219   void orq(Register dst, Register src);
  1221   void popl(Address dst);
  1223 #ifdef _LP64
  1224   void popq(Address dst);
  1225 #endif
  1227   void popcntl(Register dst, Address src);
  1228   void popcntl(Register dst, Register src);
  1230 #ifdef _LP64
  1231   void popcntq(Register dst, Address src);
  1232   void popcntq(Register dst, Register src);
  1233 #endif
  1235   // Prefetches (SSE, SSE2, 3DNOW only)
  1237   void prefetchnta(Address src);
  1238   void prefetchr(Address src);
  1239   void prefetcht0(Address src);
  1240   void prefetcht1(Address src);
  1241   void prefetcht2(Address src);
  1242   void prefetchw(Address src);
  1244   // Shuffle Packed Doublewords
  1245   void pshufd(XMMRegister dst, XMMRegister src, int mode);
  1246   void pshufd(XMMRegister dst, Address src,     int mode);
  1248   // Shuffle Packed Low Words
  1249   void pshuflw(XMMRegister dst, XMMRegister src, int mode);
  1250   void pshuflw(XMMRegister dst, Address src,     int mode);
  1252   // Shift Right Logical Quadword Immediate
  1253   void psrlq(XMMRegister dst, int shift);
  1255   // Interleave Low Bytes
  1256   void punpcklbw(XMMRegister dst, XMMRegister src);
  1258   void pushl(Address src);
  1260   void pushq(Address src);
  1262   // Xor Packed Byte Integer Values
  1263   void pxor(XMMRegister dst, Address src);
  1264   void pxor(XMMRegister dst, XMMRegister src);
  1266   void rcll(Register dst, int imm8);
  1268   void rclq(Register dst, int imm8);
  1270   void ret(int imm16);
  1272   void sahf();
  1274   void sarl(Register dst, int imm8);
  1275   void sarl(Register dst);
  1277   void sarq(Register dst, int imm8);
  1278   void sarq(Register dst);
  1280   void sbbl(Address dst, int32_t imm32);
  1281   void sbbl(Register dst, int32_t imm32);
  1282   void sbbl(Register dst, Address src);
  1283   void sbbl(Register dst, Register src);
  1285   void sbbq(Address dst, int32_t imm32);
  1286   void sbbq(Register dst, int32_t imm32);
  1287   void sbbq(Register dst, Address src);
  1288   void sbbq(Register dst, Register src);
  1290   void setb(Condition cc, Register dst);
  1292   void shldl(Register dst, Register src);
  1294   void shll(Register dst, int imm8);
  1295   void shll(Register dst);
  1297   void shlq(Register dst, int imm8);
  1298   void shlq(Register dst);
  1300   void shrdl(Register dst, Register src);
  1302   void shrl(Register dst, int imm8);
  1303   void shrl(Register dst);
  1305   void shrq(Register dst, int imm8);
  1306   void shrq(Register dst);
  1308   void smovl(); // QQQ generic?
  1310   // Compute Square Root of Scalar Double-Precision Floating-Point Value
  1311   void sqrtsd(XMMRegister dst, Address src);
  1312   void sqrtsd(XMMRegister dst, XMMRegister src);
  1314   void std() { emit_byte(0xfd); }
  1316   void stmxcsr( Address dst );
  1318   void subl(Address dst, int32_t imm32);
  1319   void subl(Address dst, Register src);
  1320   void subl(Register dst, int32_t imm32);
  1321   void subl(Register dst, Address src);
  1322   void subl(Register dst, Register src);
  1324   void subq(Address dst, int32_t imm32);
  1325   void subq(Address dst, Register src);
  1326   void subq(Register dst, int32_t imm32);
  1327   void subq(Register dst, Address src);
  1328   void subq(Register dst, Register src);
  1331   // Subtract Scalar Double-Precision Floating-Point Values
  1332   void subsd(XMMRegister dst, Address src);
  1333   void subsd(XMMRegister dst, XMMRegister src);
  1335   // Subtract Scalar Single-Precision Floating-Point Values
  1336   void subss(XMMRegister dst, Address src);
  1337   void subss(XMMRegister dst, XMMRegister src);
  1339   void testb(Register dst, int imm8);
  1341   void testl(Register dst, int32_t imm32);
  1342   void testl(Register dst, Register src);
  1343   void testl(Register dst, Address src);
  1345   void testq(Register dst, int32_t imm32);
  1346   void testq(Register dst, Register src);
  1349   // Unordered Compare Scalar Double-Precision Floating-Point Values and set EFLAGS
  1350   void ucomisd(XMMRegister dst, Address src);
  1351   void ucomisd(XMMRegister dst, XMMRegister src);
  1353   // Unordered Compare Scalar Single-Precision Floating-Point Values and set EFLAGS
  1354   void ucomiss(XMMRegister dst, Address src);
  1355   void ucomiss(XMMRegister dst, XMMRegister src);
  1357   void xaddl(Address dst, Register src);
  1359   void xaddq(Address dst, Register src);
  1361   void xchgl(Register reg, Address adr);
  1362   void xchgl(Register dst, Register src);
  1364   void xchgq(Register reg, Address adr);
  1365   void xchgq(Register dst, Register src);
  1367   void xorl(Register dst, int32_t imm32);
  1368   void xorl(Register dst, Address src);
  1369   void xorl(Register dst, Register src);
  1371   void xorq(Register dst, Address src);
  1372   void xorq(Register dst, Register src);
  1374   // Bitwise Logical XOR of Packed Double-Precision Floating-Point Values
  1375   void xorpd(XMMRegister dst, Address src);
  1376   void xorpd(XMMRegister dst, XMMRegister src);
  1378   // Bitwise Logical XOR of Packed Single-Precision Floating-Point Values
  1379   void xorps(XMMRegister dst, Address src);
  1380   void xorps(XMMRegister dst, XMMRegister src);
  1382   void set_byte_if_not_zero(Register dst); // sets reg to 1 if not zero, otherwise 0
  1383 };
  1386 // MacroAssembler extends Assembler by frequently used macros.
  1387 //
  1388 // Instructions for which a 'better' code sequence exists depending
  1389 // on arguments should also go in here.
  1391 class MacroAssembler: public Assembler {
  1392   friend class LIR_Assembler;
  1393   friend class Runtime1;      // as_Address()
  1394  protected:
  1396   Address as_Address(AddressLiteral adr);
  1397   Address as_Address(ArrayAddress adr);
  1399   // Support for VM calls
  1400   //
  1401   // This is the base routine called by the different versions of call_VM_leaf. The interpreter
  1402   // may customize this version by overriding it for its purposes (e.g., to save/restore
  1403   // additional registers when doing a VM call).
  1404 #ifdef CC_INTERP
  1405   // c++ interpreter never wants to use interp_masm version of call_VM
  1406   #define VIRTUAL
  1407 #else
  1408   #define VIRTUAL virtual
  1409 #endif
  1411   VIRTUAL void call_VM_leaf_base(
  1412     address entry_point,               // the entry point
  1413     int     number_of_arguments        // the number of arguments to pop after the call
  1414   );
  1416   // This is the base routine called by the different versions of call_VM. The interpreter
  1417   // may customize this version by overriding it for its purposes (e.g., to save/restore
  1418   // additional registers when doing a VM call).
  1419   //
  1420   // If no java_thread register is specified (noreg) than rdi will be used instead. call_VM_base
  1421   // returns the register which contains the thread upon return. If a thread register has been
  1422   // specified, the return value will correspond to that register. If no last_java_sp is specified
  1423   // (noreg) than rsp will be used instead.
  1424   VIRTUAL void call_VM_base(           // returns the register containing the thread upon return
  1425     Register oop_result,               // where an oop-result ends up if any; use noreg otherwise
  1426     Register java_thread,              // the thread if computed before     ; use noreg otherwise
  1427     Register last_java_sp,             // to set up last_Java_frame in stubs; use noreg otherwise
  1428     address  entry_point,              // the entry point
  1429     int      number_of_arguments,      // the number of arguments (w/o thread) to pop after the call
  1430     bool     check_exceptions          // whether to check for pending exceptions after return
  1431   );
  1433   // These routines should emit JVMTI PopFrame and ForceEarlyReturn handling code.
  1434   // The implementation is only non-empty for the InterpreterMacroAssembler,
  1435   // as only the interpreter handles PopFrame and ForceEarlyReturn requests.
  1436   virtual void check_and_handle_popframe(Register java_thread);
  1437   virtual void check_and_handle_earlyret(Register java_thread);
  1439   void call_VM_helper(Register oop_result, address entry_point, int number_of_arguments, bool check_exceptions = true);
  1441   // helpers for FPU flag access
  1442   // tmp is a temporary register, if none is available use noreg
  1443   void save_rax   (Register tmp);
  1444   void restore_rax(Register tmp);
  1446  public:
  1447   MacroAssembler(CodeBuffer* code) : Assembler(code) {}
  1449   // Support for NULL-checks
  1450   //
  1451   // Generates code that causes a NULL OS exception if the content of reg is NULL.
  1452   // If the accessed location is M[reg + offset] and the offset is known, provide the
  1453   // offset. No explicit code generation is needed if the offset is within a certain
  1454   // range (0 <= offset <= page_size).
  1456   void null_check(Register reg, int offset = -1);
  1457   static bool needs_explicit_null_check(intptr_t offset);
  1459   // Required platform-specific helpers for Label::patch_instructions.
  1460   // They _shadow_ the declarations in AbstractAssembler, which are undefined.
  1461   void pd_patch_instruction(address branch, address target);
  1462 #ifndef PRODUCT
  1463   static void pd_print_patched_instruction(address branch);
  1464 #endif
  1466   // The following 4 methods return the offset of the appropriate move instruction
  1468   // Support for fast byte/short loading with zero extension (depending on particular CPU)
  1469   int load_unsigned_byte(Register dst, Address src);
  1470   int load_unsigned_short(Register dst, Address src);
  1472   // Support for fast byte/short loading with sign extension (depending on particular CPU)
  1473   int load_signed_byte(Register dst, Address src);
  1474   int load_signed_short(Register dst, Address src);
  1476   // Support for sign-extension (hi:lo = extend_sign(lo))
  1477   void extend_sign(Register hi, Register lo);
  1479   // Loading values by size and signed-ness
  1480   void load_sized_value(Register dst, Address src, int size_in_bytes, bool is_signed);
  1482   // Support for inc/dec with optimal instruction selection depending on value
  1484   void increment(Register reg, int value = 1) { LP64_ONLY(incrementq(reg, value)) NOT_LP64(incrementl(reg, value)) ; }
  1485   void decrement(Register reg, int value = 1) { LP64_ONLY(decrementq(reg, value)) NOT_LP64(decrementl(reg, value)) ; }
  1487   void decrementl(Address dst, int value = 1);
  1488   void decrementl(Register reg, int value = 1);
  1490   void decrementq(Register reg, int value = 1);
  1491   void decrementq(Address dst, int value = 1);
  1493   void incrementl(Address dst, int value = 1);
  1494   void incrementl(Register reg, int value = 1);
  1496   void incrementq(Register reg, int value = 1);
  1497   void incrementq(Address dst, int value = 1);
  1500   // Support optimal SSE move instructions.
  1501   void movflt(XMMRegister dst, XMMRegister src) {
  1502     if (UseXmmRegToRegMoveAll) { movaps(dst, src); return; }
  1503     else                       { movss (dst, src); return; }
  1505   void movflt(XMMRegister dst, Address src) { movss(dst, src); }
  1506   void movflt(XMMRegister dst, AddressLiteral src);
  1507   void movflt(Address dst, XMMRegister src) { movss(dst, src); }
  1509   void movdbl(XMMRegister dst, XMMRegister src) {
  1510     if (UseXmmRegToRegMoveAll) { movapd(dst, src); return; }
  1511     else                       { movsd (dst, src); return; }
  1514   void movdbl(XMMRegister dst, AddressLiteral src);
  1516   void movdbl(XMMRegister dst, Address src) {
  1517     if (UseXmmLoadAndClearUpper) { movsd (dst, src); return; }
  1518     else                         { movlpd(dst, src); return; }
  1520   void movdbl(Address dst, XMMRegister src) { movsd(dst, src); }
  1522   void incrementl(AddressLiteral dst);
  1523   void incrementl(ArrayAddress dst);
  1525   // Alignment
  1526   void align(int modulus);
  1528   // Misc
  1529   void fat_nop(); // 5 byte nop
  1531   // Stack frame creation/removal
  1532   void enter();
  1533   void leave();
  1535   // Support for getting the JavaThread pointer (i.e.; a reference to thread-local information)
  1536   // The pointer will be loaded into the thread register.
  1537   void get_thread(Register thread);
  1540   // Support for VM calls
  1541   //
  1542   // It is imperative that all calls into the VM are handled via the call_VM macros.
  1543   // They make sure that the stack linkage is setup correctly. call_VM's correspond
  1544   // to ENTRY/ENTRY_X entry points while call_VM_leaf's correspond to LEAF entry points.
  1547   void call_VM(Register oop_result,
  1548                address entry_point,
  1549                bool check_exceptions = true);
  1550   void call_VM(Register oop_result,
  1551                address entry_point,
  1552                Register arg_1,
  1553                bool check_exceptions = true);
  1554   void call_VM(Register oop_result,
  1555                address entry_point,
  1556                Register arg_1, Register arg_2,
  1557                bool check_exceptions = true);
  1558   void call_VM(Register oop_result,
  1559                address entry_point,
  1560                Register arg_1, Register arg_2, Register arg_3,
  1561                bool check_exceptions = true);
  1563   // Overloadings with last_Java_sp
  1564   void call_VM(Register oop_result,
  1565                Register last_java_sp,
  1566                address entry_point,
  1567                int number_of_arguments = 0,
  1568                bool check_exceptions = true);
  1569   void call_VM(Register oop_result,
  1570                Register last_java_sp,
  1571                address entry_point,
  1572                Register arg_1, bool
  1573                check_exceptions = true);
  1574   void call_VM(Register oop_result,
  1575                Register last_java_sp,
  1576                address entry_point,
  1577                Register arg_1, Register arg_2,
  1578                bool check_exceptions = true);
  1579   void call_VM(Register oop_result,
  1580                Register last_java_sp,
  1581                address entry_point,
  1582                Register arg_1, Register arg_2, Register arg_3,
  1583                bool check_exceptions = true);
  1585   void call_VM_leaf(address entry_point,
  1586                     int number_of_arguments = 0);
  1587   void call_VM_leaf(address entry_point,
  1588                     Register arg_1);
  1589   void call_VM_leaf(address entry_point,
  1590                     Register arg_1, Register arg_2);
  1591   void call_VM_leaf(address entry_point,
  1592                     Register arg_1, Register arg_2, Register arg_3);
  1594   // last Java Frame (fills frame anchor)
  1595   void set_last_Java_frame(Register thread,
  1596                            Register last_java_sp,
  1597                            Register last_java_fp,
  1598                            address last_java_pc);
  1600   // thread in the default location (r15_thread on 64bit)
  1601   void set_last_Java_frame(Register last_java_sp,
  1602                            Register last_java_fp,
  1603                            address last_java_pc);
  1605   void reset_last_Java_frame(Register thread, bool clear_fp, bool clear_pc);
  1607   // thread in the default location (r15_thread on 64bit)
  1608   void reset_last_Java_frame(bool clear_fp, bool clear_pc);
  1610   // Stores
  1611   void store_check(Register obj);                // store check for obj - register is destroyed afterwards
  1612   void store_check(Register obj, Address dst);   // same as above, dst is exact store location (reg. is destroyed)
  1614   void g1_write_barrier_pre(Register obj,
  1615 #ifndef _LP64
  1616                             Register thread,
  1617 #endif
  1618                             Register tmp,
  1619                             Register tmp2,
  1620                             bool     tosca_live);
  1621   void g1_write_barrier_post(Register store_addr,
  1622                              Register new_val,
  1623 #ifndef _LP64
  1624                              Register thread,
  1625 #endif
  1626                              Register tmp,
  1627                              Register tmp2);
  1630   // split store_check(Register obj) to enhance instruction interleaving
  1631   void store_check_part_1(Register obj);
  1632   void store_check_part_2(Register obj);
  1634   // C 'boolean' to Java boolean: x == 0 ? 0 : 1
  1635   void c2bool(Register x);
  1637   // C++ bool manipulation
  1639   void movbool(Register dst, Address src);
  1640   void movbool(Address dst, bool boolconst);
  1641   void movbool(Address dst, Register src);
  1642   void testbool(Register dst);
  1644   // oop manipulations
  1645   void load_klass(Register dst, Register src);
  1646   void store_klass(Register dst, Register src);
  1648   void load_prototype_header(Register dst, Register src);
  1650 #ifdef _LP64
  1651   void store_klass_gap(Register dst, Register src);
  1653   void load_heap_oop(Register dst, Address src);
  1654   void store_heap_oop(Address dst, Register src);
  1655   void encode_heap_oop(Register r);
  1656   void decode_heap_oop(Register r);
  1657   void encode_heap_oop_not_null(Register r);
  1658   void decode_heap_oop_not_null(Register r);
  1659   void encode_heap_oop_not_null(Register dst, Register src);
  1660   void decode_heap_oop_not_null(Register dst, Register src);
  1662   void set_narrow_oop(Register dst, jobject obj);
  1663   void set_narrow_oop(Address dst, jobject obj);
  1664   void cmp_narrow_oop(Register dst, jobject obj);
  1665   void cmp_narrow_oop(Address dst, jobject obj);
  1667   // if heap base register is used - reinit it with the correct value
  1668   void reinit_heapbase();
  1669 #endif // _LP64
  1671   // Int division/remainder for Java
  1672   // (as idivl, but checks for special case as described in JVM spec.)
  1673   // returns idivl instruction offset for implicit exception handling
  1674   int corrected_idivl(Register reg);
  1676   // Long division/remainder for Java
  1677   // (as idivq, but checks for special case as described in JVM spec.)
  1678   // returns idivq instruction offset for implicit exception handling
  1679   int corrected_idivq(Register reg);
  1681   void int3();
  1683   // Long operation macros for a 32bit cpu
  1684   // Long negation for Java
  1685   void lneg(Register hi, Register lo);
  1687   // Long multiplication for Java
  1688   // (destroys contents of eax, ebx, ecx and edx)
  1689   void lmul(int x_rsp_offset, int y_rsp_offset); // rdx:rax = x * y
  1691   // Long shifts for Java
  1692   // (semantics as described in JVM spec.)
  1693   void lshl(Register hi, Register lo);                               // hi:lo << (rcx & 0x3f)
  1694   void lshr(Register hi, Register lo, bool sign_extension = false);  // hi:lo >> (rcx & 0x3f)
  1696   // Long compare for Java
  1697   // (semantics as described in JVM spec.)
  1698   void lcmp2int(Register x_hi, Register x_lo, Register y_hi, Register y_lo); // x_hi = lcmp(x, y)
  1701   // misc
  1703   // Sign extension
  1704   void sign_extend_short(Register reg);
  1705   void sign_extend_byte(Register reg);
  1707   // Division by power of 2, rounding towards 0
  1708   void division_with_shift(Register reg, int shift_value);
  1710   // Compares the top-most stack entries on the FPU stack and sets the eflags as follows:
  1711   //
  1712   // CF (corresponds to C0) if x < y
  1713   // PF (corresponds to C2) if unordered
  1714   // ZF (corresponds to C3) if x = y
  1715   //
  1716   // The arguments are in reversed order on the stack (i.e., top of stack is first argument).
  1717   // tmp is a temporary register, if none is available use noreg (only matters for non-P6 code)
  1718   void fcmp(Register tmp);
  1719   // Variant of the above which allows y to be further down the stack
  1720   // and which only pops x and y if specified. If pop_right is
  1721   // specified then pop_left must also be specified.
  1722   void fcmp(Register tmp, int index, bool pop_left, bool pop_right);
  1724   // Floating-point comparison for Java
  1725   // Compares the top-most stack entries on the FPU stack and stores the result in dst.
  1726   // The arguments are in reversed order on the stack (i.e., top of stack is first argument).
  1727   // (semantics as described in JVM spec.)
  1728   void fcmp2int(Register dst, bool unordered_is_less);
  1729   // Variant of the above which allows y to be further down the stack
  1730   // and which only pops x and y if specified. If pop_right is
  1731   // specified then pop_left must also be specified.
  1732   void fcmp2int(Register dst, bool unordered_is_less, int index, bool pop_left, bool pop_right);
  1734   // Floating-point remainder for Java (ST0 = ST0 fremr ST1, ST1 is empty afterwards)
  1735   // tmp is a temporary register, if none is available use noreg
  1736   void fremr(Register tmp);
  1739   // same as fcmp2int, but using SSE2
  1740   void cmpss2int(XMMRegister opr1, XMMRegister opr2, Register dst, bool unordered_is_less);
  1741   void cmpsd2int(XMMRegister opr1, XMMRegister opr2, Register dst, bool unordered_is_less);
  1743   // Inlined sin/cos generator for Java; must not use CPU instruction
  1744   // directly on Intel as it does not have high enough precision
  1745   // outside of the range [-pi/4, pi/4]. Extra argument indicate the
  1746   // number of FPU stack slots in use; all but the topmost will
  1747   // require saving if a slow case is necessary. Assumes argument is
  1748   // on FP TOS; result is on FP TOS.  No cpu registers are changed by
  1749   // this code.
  1750   void trigfunc(char trig, int num_fpu_regs_in_use = 1);
  1752   // branch to L if FPU flag C2 is set/not set
  1753   // tmp is a temporary register, if none is available use noreg
  1754   void jC2 (Register tmp, Label& L);
  1755   void jnC2(Register tmp, Label& L);
  1757   // Pop ST (ffree & fincstp combined)
  1758   void fpop();
  1760   // pushes double TOS element of FPU stack on CPU stack; pops from FPU stack
  1761   void push_fTOS();
  1763   // pops double TOS element from CPU stack and pushes on FPU stack
  1764   void pop_fTOS();
  1766   void empty_FPU_stack();
  1768   void push_IU_state();
  1769   void pop_IU_state();
  1771   void push_FPU_state();
  1772   void pop_FPU_state();
  1774   void push_CPU_state();
  1775   void pop_CPU_state();
  1777   // Round up to a power of two
  1778   void round_to(Register reg, int modulus);
  1780   // Callee saved registers handling
  1781   void push_callee_saved_registers();
  1782   void pop_callee_saved_registers();
  1784   // allocation
  1785   void eden_allocate(
  1786     Register obj,                      // result: pointer to object after successful allocation
  1787     Register var_size_in_bytes,        // object size in bytes if unknown at compile time; invalid otherwise
  1788     int      con_size_in_bytes,        // object size in bytes if   known at compile time
  1789     Register t1,                       // temp register
  1790     Label&   slow_case                 // continuation point if fast allocation fails
  1791   );
  1792   void tlab_allocate(
  1793     Register obj,                      // result: pointer to object after successful allocation
  1794     Register var_size_in_bytes,        // object size in bytes if unknown at compile time; invalid otherwise
  1795     int      con_size_in_bytes,        // object size in bytes if   known at compile time
  1796     Register t1,                       // temp register
  1797     Register t2,                       // temp register
  1798     Label&   slow_case                 // continuation point if fast allocation fails
  1799   );
  1800   void tlab_refill(Label& retry_tlab, Label& try_eden, Label& slow_case);
  1802   // interface method calling
  1803   void lookup_interface_method(Register recv_klass,
  1804                                Register intf_klass,
  1805                                RegisterConstant itable_index,
  1806                                Register method_result,
  1807                                Register scan_temp,
  1808                                Label& no_such_interface);
  1810   //----
  1811   void set_word_if_not_zero(Register reg); // sets reg to 1 if not zero, otherwise 0
  1813   // Debugging
  1815   // only if +VerifyOops
  1816   void verify_oop(Register reg, const char* s = "broken oop");
  1817   void verify_oop_addr(Address addr, const char * s = "broken oop addr");
  1819   // only if +VerifyFPU
  1820   void verify_FPU(int stack_depth, const char* s = "illegal FPU state");
  1822   // prints msg, dumps registers and stops execution
  1823   void stop(const char* msg);
  1825   // prints msg and continues
  1826   void warn(const char* msg);
  1828   static void debug32(int rdi, int rsi, int rbp, int rsp, int rbx, int rdx, int rcx, int rax, int eip, char* msg);
  1829   static void debug64(char* msg, int64_t pc, int64_t regs[]);
  1831   void os_breakpoint();
  1833   void untested()                                { stop("untested"); }
  1835   void unimplemented(const char* what = "")      { char* b = new char[1024];  jio_snprintf(b, sizeof(b), "unimplemented: %s", what);  stop(b); }
  1837   void should_not_reach_here()                   { stop("should not reach here"); }
  1839   void print_CPU_state();
  1841   // Stack overflow checking
  1842   void bang_stack_with_offset(int offset) {
  1843     // stack grows down, caller passes positive offset
  1844     assert(offset > 0, "must bang with negative offset");
  1845     movl(Address(rsp, (-offset)), rax);
  1848   // Writes to stack successive pages until offset reached to check for
  1849   // stack overflow + shadow pages.  Also, clobbers tmp
  1850   void bang_stack_size(Register size, Register tmp);
  1852   virtual RegisterConstant delayed_value(intptr_t* delayed_value_addr,
  1853                                          Register tmp,
  1854                                          int offset);
  1856   // Support for serializing memory accesses between threads
  1857   void serialize_memory(Register thread, Register tmp);
  1859   void verify_tlab();
  1861   // Biased locking support
  1862   // lock_reg and obj_reg must be loaded up with the appropriate values.
  1863   // swap_reg must be rax, and is killed.
  1864   // tmp_reg is optional. If it is supplied (i.e., != noreg) it will
  1865   // be killed; if not supplied, push/pop will be used internally to
  1866   // allocate a temporary (inefficient, avoid if possible).
  1867   // Optional slow case is for implementations (interpreter and C1) which branch to
  1868   // slow case directly. Leaves condition codes set for C2's Fast_Lock node.
  1869   // Returns offset of first potentially-faulting instruction for null
  1870   // check info (currently consumed only by C1). If
  1871   // swap_reg_contains_mark is true then returns -1 as it is assumed
  1872   // the calling code has already passed any potential faults.
  1873   int biased_locking_enter(Register lock_reg, Register obj_reg,
  1874                            Register swap_reg, Register tmp_reg,
  1875                            bool swap_reg_contains_mark,
  1876                            Label& done, Label* slow_case = NULL,
  1877                            BiasedLockingCounters* counters = NULL);
  1878   void biased_locking_exit (Register obj_reg, Register temp_reg, Label& done);
  1881   Condition negate_condition(Condition cond);
  1883   // Instructions that use AddressLiteral operands. These instruction can handle 32bit/64bit
  1884   // operands. In general the names are modified to avoid hiding the instruction in Assembler
  1885   // so that we don't need to implement all the varieties in the Assembler with trivial wrappers
  1886   // here in MacroAssembler. The major exception to this rule is call
  1888   // Arithmetics
  1891   void addptr(Address dst, int32_t src) { LP64_ONLY(addq(dst, src)) NOT_LP64(addl(dst, src)) ; }
  1892   void addptr(Address dst, Register src);
  1894   void addptr(Register dst, Address src) { LP64_ONLY(addq(dst, src)) NOT_LP64(addl(dst, src)); }
  1895   void addptr(Register dst, int32_t src);
  1896   void addptr(Register dst, Register src);
  1898   void andptr(Register dst, int32_t src);
  1899   void andptr(Register src1, Register src2) { LP64_ONLY(andq(src1, src2)) NOT_LP64(andl(src1, src2)) ; }
  1901   void cmp8(AddressLiteral src1, int imm);
  1903   // renamed to drag out the casting of address to int32_t/intptr_t
  1904   void cmp32(Register src1, int32_t imm);
  1906   void cmp32(AddressLiteral src1, int32_t imm);
  1907   // compare reg - mem, or reg - &mem
  1908   void cmp32(Register src1, AddressLiteral src2);
  1910   void cmp32(Register src1, Address src2);
  1912 #ifndef _LP64
  1913   void cmpoop(Address dst, jobject obj);
  1914   void cmpoop(Register dst, jobject obj);
  1915 #endif // _LP64
  1917   // NOTE src2 must be the lval. This is NOT an mem-mem compare
  1918   void cmpptr(Address src1, AddressLiteral src2);
  1920   void cmpptr(Register src1, AddressLiteral src2);
  1922   void cmpptr(Register src1, Register src2) { LP64_ONLY(cmpq(src1, src2)) NOT_LP64(cmpl(src1, src2)) ; }
  1923   void cmpptr(Register src1, Address src2) { LP64_ONLY(cmpq(src1, src2)) NOT_LP64(cmpl(src1, src2)) ; }
  1924   // void cmpptr(Address src1, Register src2) { LP64_ONLY(cmpq(src1, src2)) NOT_LP64(cmpl(src1, src2)) ; }
  1926   void cmpptr(Register src1, int32_t src2) { LP64_ONLY(cmpq(src1, src2)) NOT_LP64(cmpl(src1, src2)) ; }
  1927   void cmpptr(Address src1, int32_t src2) { LP64_ONLY(cmpq(src1, src2)) NOT_LP64(cmpl(src1, src2)) ; }
  1929   // cmp64 to avoild hiding cmpq
  1930   void cmp64(Register src1, AddressLiteral src);
  1932   void cmpxchgptr(Register reg, Address adr);
  1934   void locked_cmpxchgptr(Register reg, AddressLiteral adr);
  1937   void imulptr(Register dst, Register src) { LP64_ONLY(imulq(dst, src)) NOT_LP64(imull(dst, src)); }
  1940   void negptr(Register dst) { LP64_ONLY(negq(dst)) NOT_LP64(negl(dst)); }
  1942   void notptr(Register dst) { LP64_ONLY(notq(dst)) NOT_LP64(notl(dst)); }
  1944   void shlptr(Register dst, int32_t shift);
  1945   void shlptr(Register dst) { LP64_ONLY(shlq(dst)) NOT_LP64(shll(dst)); }
  1947   void shrptr(Register dst, int32_t shift);
  1948   void shrptr(Register dst) { LP64_ONLY(shrq(dst)) NOT_LP64(shrl(dst)); }
  1950   void sarptr(Register dst) { LP64_ONLY(sarq(dst)) NOT_LP64(sarl(dst)); }
  1951   void sarptr(Register dst, int32_t src) { LP64_ONLY(sarq(dst, src)) NOT_LP64(sarl(dst, src)); }
  1953   void subptr(Address dst, int32_t src) { LP64_ONLY(subq(dst, src)) NOT_LP64(subl(dst, src)); }
  1955   void subptr(Register dst, Address src) { LP64_ONLY(subq(dst, src)) NOT_LP64(subl(dst, src)); }
  1956   void subptr(Register dst, int32_t src);
  1957   void subptr(Register dst, Register src);
  1960   void sbbptr(Address dst, int32_t src) { LP64_ONLY(sbbq(dst, src)) NOT_LP64(sbbl(dst, src)); }
  1961   void sbbptr(Register dst, int32_t src) { LP64_ONLY(sbbq(dst, src)) NOT_LP64(sbbl(dst, src)); }
  1963   void xchgptr(Register src1, Register src2) { LP64_ONLY(xchgq(src1, src2)) NOT_LP64(xchgl(src1, src2)) ; }
  1964   void xchgptr(Register src1, Address src2) { LP64_ONLY(xchgq(src1, src2)) NOT_LP64(xchgl(src1, src2)) ; }
  1966   void xaddptr(Address src1, Register src2) { LP64_ONLY(xaddq(src1, src2)) NOT_LP64(xaddl(src1, src2)) ; }
  1970   // Helper functions for statistics gathering.
  1971   // Conditionally (atomically, on MPs) increments passed counter address, preserving condition codes.
  1972   void cond_inc32(Condition cond, AddressLiteral counter_addr);
  1973   // Unconditional atomic increment.
  1974   void atomic_incl(AddressLiteral counter_addr);
  1976   void lea(Register dst, AddressLiteral adr);
  1977   void lea(Address dst, AddressLiteral adr);
  1978   void lea(Register dst, Address adr) { Assembler::lea(dst, adr); }
  1980   void leal32(Register dst, Address src) { leal(dst, src); }
  1982   void test32(Register src1, AddressLiteral src2);
  1984   void orptr(Register dst, Address src) { LP64_ONLY(orq(dst, src)) NOT_LP64(orl(dst, src)); }
  1985   void orptr(Register dst, Register src) { LP64_ONLY(orq(dst, src)) NOT_LP64(orl(dst, src)); }
  1986   void orptr(Register dst, int32_t src) { LP64_ONLY(orq(dst, src)) NOT_LP64(orl(dst, src)); }
  1988   void testptr(Register src, int32_t imm32) {  LP64_ONLY(testq(src, imm32)) NOT_LP64(testl(src, imm32)); }
  1989   void testptr(Register src1, Register src2);
  1991   void xorptr(Register dst, Register src) { LP64_ONLY(xorq(dst, src)) NOT_LP64(xorl(dst, src)); }
  1992   void xorptr(Register dst, Address src) { LP64_ONLY(xorq(dst, src)) NOT_LP64(xorl(dst, src)); }
  1994   // Calls
  1996   void call(Label& L, relocInfo::relocType rtype);
  1997   void call(Register entry);
  1999   // NOTE: this call tranfers to the effective address of entry NOT
  2000   // the address contained by entry. This is because this is more natural
  2001   // for jumps/calls.
  2002   void call(AddressLiteral entry);
  2004   // Jumps
  2006   // NOTE: these jumps tranfer to the effective address of dst NOT
  2007   // the address contained by dst. This is because this is more natural
  2008   // for jumps/calls.
  2009   void jump(AddressLiteral dst);
  2010   void jump_cc(Condition cc, AddressLiteral dst);
  2012   // 32bit can do a case table jump in one instruction but we no longer allow the base
  2013   // to be installed in the Address class. This jump will tranfers to the address
  2014   // contained in the location described by entry (not the address of entry)
  2015   void jump(ArrayAddress entry);
  2017   // Floating
  2019   void andpd(XMMRegister dst, Address src) { Assembler::andpd(dst, src); }
  2020   void andpd(XMMRegister dst, AddressLiteral src);
  2022   void comiss(XMMRegister dst, Address src) { Assembler::comiss(dst, src); }
  2023   void comiss(XMMRegister dst, AddressLiteral src);
  2025   void comisd(XMMRegister dst, Address src) { Assembler::comisd(dst, src); }
  2026   void comisd(XMMRegister dst, AddressLiteral src);
  2028   void fldcw(Address src) { Assembler::fldcw(src); }
  2029   void fldcw(AddressLiteral src);
  2031   void fld_s(int index)   { Assembler::fld_s(index); }
  2032   void fld_s(Address src) { Assembler::fld_s(src); }
  2033   void fld_s(AddressLiteral src);
  2035   void fld_d(Address src) { Assembler::fld_d(src); }
  2036   void fld_d(AddressLiteral src);
  2038   void fld_x(Address src) { Assembler::fld_x(src); }
  2039   void fld_x(AddressLiteral src);
  2041   void ldmxcsr(Address src) { Assembler::ldmxcsr(src); }
  2042   void ldmxcsr(AddressLiteral src);
  2044 private:
  2045   // these are private because users should be doing movflt/movdbl
  2047   void movss(Address dst, XMMRegister src)     { Assembler::movss(dst, src); }
  2048   void movss(XMMRegister dst, XMMRegister src) { Assembler::movss(dst, src); }
  2049   void movss(XMMRegister dst, Address src)     { Assembler::movss(dst, src); }
  2050   void movss(XMMRegister dst, AddressLiteral src);
  2052   void movlpd(XMMRegister dst, Address src)      {Assembler::movlpd(dst, src); }
  2053   void movlpd(XMMRegister dst, AddressLiteral src);
  2055 public:
  2057   void movsd(XMMRegister dst, XMMRegister src) { Assembler::movsd(dst, src); }
  2058   void movsd(Address dst, XMMRegister src)     { Assembler::movsd(dst, src); }
  2059   void movsd(XMMRegister dst, Address src)     { Assembler::movsd(dst, src); }
  2060   void movsd(XMMRegister dst, AddressLiteral src);
  2062   void ucomiss(XMMRegister dst, XMMRegister src) { Assembler::ucomiss(dst, src); }
  2063   void ucomiss(XMMRegister dst, Address src) { Assembler::ucomiss(dst, src); }
  2064   void ucomiss(XMMRegister dst, AddressLiteral src);
  2066   void ucomisd(XMMRegister dst, XMMRegister src) { Assembler::ucomisd(dst, src); }
  2067   void ucomisd(XMMRegister dst, Address src) { Assembler::ucomisd(dst, src); }
  2068   void ucomisd(XMMRegister dst, AddressLiteral src);
  2070   // Bitwise Logical XOR of Packed Double-Precision Floating-Point Values
  2071   void xorpd(XMMRegister dst, XMMRegister src) { Assembler::xorpd(dst, src); }
  2072   void xorpd(XMMRegister dst, Address src)     { Assembler::xorpd(dst, src); }
  2073   void xorpd(XMMRegister dst, AddressLiteral src);
  2075   // Bitwise Logical XOR of Packed Single-Precision Floating-Point Values
  2076   void xorps(XMMRegister dst, XMMRegister src) { Assembler::xorps(dst, src); }
  2077   void xorps(XMMRegister dst, Address src)     { Assembler::xorps(dst, src); }
  2078   void xorps(XMMRegister dst, AddressLiteral src);
  2080   // Data
  2082   void cmov(Condition cc, Register dst, Register src) { LP64_ONLY(cmovq(cc, dst, src)) NOT_LP64(cmovl(cc, dst, src)); }
  2084   void cmovptr(Condition cc, Register dst, Address src) { LP64_ONLY(cmovq(cc, dst, src)) NOT_LP64(cmovl(cc, dst, src)); }
  2085   void cmovptr(Condition cc, Register dst, Register src) { LP64_ONLY(cmovq(cc, dst, src)) NOT_LP64(cmovl(cc, dst, src)); }
  2087   void movoop(Register dst, jobject obj);
  2088   void movoop(Address dst, jobject obj);
  2090   void movptr(ArrayAddress dst, Register src);
  2091   // can this do an lea?
  2092   void movptr(Register dst, ArrayAddress src);
  2094   void movptr(Register dst, Address src);
  2096   void movptr(Register dst, AddressLiteral src);
  2098   void movptr(Register dst, intptr_t src);
  2099   void movptr(Register dst, Register src);
  2100   void movptr(Address dst, intptr_t src);
  2102   void movptr(Address dst, Register src);
  2104 #ifdef _LP64
  2105   // Generally the next two are only used for moving NULL
  2106   // Although there are situations in initializing the mark word where
  2107   // they could be used. They are dangerous.
  2109   // They only exist on LP64 so that int32_t and intptr_t are not the same
  2110   // and we have ambiguous declarations.
  2112   void movptr(Address dst, int32_t imm32);
  2113   void movptr(Register dst, int32_t imm32);
  2114 #endif // _LP64
  2116   // to avoid hiding movl
  2117   void mov32(AddressLiteral dst, Register src);
  2118   void mov32(Register dst, AddressLiteral src);
  2120   // to avoid hiding movb
  2121   void movbyte(ArrayAddress dst, int src);
  2123   // Can push value or effective address
  2124   void pushptr(AddressLiteral src);
  2126   void pushptr(Address src) { LP64_ONLY(pushq(src)) NOT_LP64(pushl(src)); }
  2127   void popptr(Address src) { LP64_ONLY(popq(src)) NOT_LP64(popl(src)); }
  2129   void pushoop(jobject obj);
  2131   // sign extend as need a l to ptr sized element
  2132   void movl2ptr(Register dst, Address src) { LP64_ONLY(movslq(dst, src)) NOT_LP64(movl(dst, src)); }
  2133   void movl2ptr(Register dst, Register src) { LP64_ONLY(movslq(dst, src)) NOT_LP64(if (dst != src) movl(dst, src)); }
  2136 #undef VIRTUAL
  2138 };
  2140 /**
  2141  * class SkipIfEqual:
  2143  * Instantiating this class will result in assembly code being output that will
  2144  * jump around any code emitted between the creation of the instance and it's
  2145  * automatic destruction at the end of a scope block, depending on the value of
  2146  * the flag passed to the constructor, which will be checked at run-time.
  2147  */
  2148 class SkipIfEqual {
  2149  private:
  2150   MacroAssembler* _masm;
  2151   Label _label;
  2153  public:
  2154    SkipIfEqual(MacroAssembler*, const bool* flag_addr, bool value);
  2155    ~SkipIfEqual();
  2156 };
  2158 #ifdef ASSERT
  2159 inline bool AbstractAssembler::pd_check_instruction_mark() { return true; }
  2160 #endif

mercurial