1 /*
   2  * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright 2012, 2018 SAP AG. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #ifndef CPU_PPC_VM_ASSEMBLER_PPC_HPP
  27 #define CPU_PPC_VM_ASSEMBLER_PPC_HPP
  28 
  29 #include "asm/register.hpp"
  30 
  31 // Address is an abstraction used to represent a memory location
  32 // as used in assembler instructions.
  33 // PPC instructions grok either baseReg + indexReg or baseReg + disp.
  34 // So far we do not use this as simplification by this class is low
  35 // on PPC with its simple addressing mode. Use RegisterOrConstant to
  36 // represent an offset.
  37 class Address VALUE_OBJ_CLASS_SPEC {
  38 };
  39 
  40 class AddressLiteral VALUE_OBJ_CLASS_SPEC {
  41  private:
  42   address          _address;
  43   RelocationHolder _rspec;
  44 
  45   RelocationHolder rspec_from_rtype(relocInfo::relocType rtype, address addr) {
  46     switch (rtype) {
  47     case relocInfo::external_word_type:
  48       return external_word_Relocation::spec(addr);
  49     case relocInfo::internal_word_type:
  50       return internal_word_Relocation::spec(addr);
  51     case relocInfo::opt_virtual_call_type:
  52       return opt_virtual_call_Relocation::spec();
  53     case relocInfo::static_call_type:
  54       return static_call_Relocation::spec();
  55     case relocInfo::runtime_call_type:
  56       return runtime_call_Relocation::spec();
  57     case relocInfo::none:
  58       return RelocationHolder();
  59     default:
  60       ShouldNotReachHere();
  61       return RelocationHolder();
  62     }
  63   }
  64 
  65  protected:
  66   // creation
  67   AddressLiteral() : _address(NULL), _rspec(NULL) {}
  68 
  69  public:
  70   AddressLiteral(address addr, RelocationHolder const& rspec)
  71     : _address(addr),
  72       _rspec(rspec) {}
  73 
  74   AddressLiteral(address addr, relocInfo::relocType rtype = relocInfo::none)
  75     : _address((address) addr),
  76       _rspec(rspec_from_rtype(rtype, (address) addr)) {}
  77 
  78   AddressLiteral(oop* addr, relocInfo::relocType rtype = relocInfo::none)
  79     : _address((address) addr),
  80       _rspec(rspec_from_rtype(rtype, (address) addr)) {}
  81 
  82   intptr_t value() const { return (intptr_t) _address; }
  83 
  84   const RelocationHolder& rspec() const { return _rspec; }
  85 };
  86 
  87 // Argument is an abstraction used to represent an outgoing
  88 // actual argument or an incoming formal parameter, whether
  89 // it resides in memory or in a register, in a manner consistent
  90 // with the PPC Application Binary Interface, or ABI. This is
  91 // often referred to as the native or C calling convention.
  92 
  93 class Argument VALUE_OBJ_CLASS_SPEC {
  94  private:
  95   int _number;  // The number of the argument.
  96  public:
  97   enum {
  98     // Only 8 registers may contain integer parameters.
  99     n_register_parameters = 8,
 100     // Can have up to 8 floating registers.
 101     n_float_register_parameters = 8,
 102 
 103     // PPC C calling conventions.
 104     // The first eight arguments are passed in int regs if they are int.
 105     n_int_register_parameters_c = 8,
 106     // The first thirteen float arguments are passed in float regs.
 107     n_float_register_parameters_c = 13,
 108     // Only the first 8 parameters are not placed on the stack. Aix disassembly
 109     // shows that xlC places all float args after argument 8 on the stack AND
 110     // in a register. This is not documented, but we follow this convention, too.
 111     n_regs_not_on_stack_c = 8,
 112   };
 113   // creation
 114   Argument(int number) : _number(number) {}
 115 
 116   int  number() const { return _number; }
 117 
 118   // Locating register-based arguments:
 119   bool is_register() const { return _number < n_register_parameters; }
 120 
 121   Register as_register() const {
 122     assert(is_register(), "must be a register argument");
 123     return as_Register(number() + R3_ARG1->encoding());
 124   }
 125 };
 126 
 127 #if !defined(ABI_ELFv2)
 128 // A ppc64 function descriptor.
 129 struct FunctionDescriptor VALUE_OBJ_CLASS_SPEC {
 130  private:
 131   address _entry;
 132   address _toc;
 133   address _env;
 134 
 135  public:
 136   inline address entry() const { return _entry; }
 137   inline address toc()   const { return _toc; }
 138   inline address env()   const { return _env; }
 139 
 140   inline void set_entry(address entry) { _entry = entry; }
 141   inline void set_toc(  address toc)   { _toc   = toc; }
 142   inline void set_env(  address env)   { _env   = env; }
 143 
 144   inline static ByteSize entry_offset() { return byte_offset_of(FunctionDescriptor, _entry); }
 145   inline static ByteSize toc_offset()   { return byte_offset_of(FunctionDescriptor, _toc); }
 146   inline static ByteSize env_offset()   { return byte_offset_of(FunctionDescriptor, _env); }
 147 
 148   // Friend functions can be called without loading toc and env.
 149   enum {
 150     friend_toc = 0xcafe,
 151     friend_env = 0xc0de
 152   };
 153 
 154   inline bool is_friend_function() const {
 155     return (toc() == (address) friend_toc) && (env() == (address) friend_env);
 156   }
 157 
 158   // Constructor for stack-allocated instances.
 159   FunctionDescriptor() {
 160     _entry = (address) 0xbad;
 161     _toc   = (address) 0xbad;
 162     _env   = (address) 0xbad;
 163   }
 164 };
 165 #endif
 166 
 167 class Assembler : public AbstractAssembler {
 168  protected:
 169   // Displacement routines
 170   static void print_instruction(int inst);
 171   static int  patched_branch(int dest_pos, int inst, int inst_pos);
 172   static int  branch_destination(int inst, int pos);
 173 
 174   friend class AbstractAssembler;
 175 
 176   // Code patchers need various routines like inv_wdisp()
 177   friend class NativeInstruction;
 178   friend class NativeGeneralJump;
 179   friend class Relocation;
 180 
 181  public:
 182 
 183   enum shifts {
 184     XO_21_29_SHIFT = 2,
 185     XO_21_30_SHIFT = 1,
 186     XO_27_29_SHIFT = 2,
 187     XO_30_31_SHIFT = 0,
 188     SPR_5_9_SHIFT  = 11u, // SPR_5_9 field in bits 11 -- 15
 189     SPR_0_4_SHIFT  = 16u, // SPR_0_4 field in bits 16 -- 20
 190     RS_SHIFT       = 21u, // RS field in bits 21 -- 25
 191     OPCODE_SHIFT   = 26u, // opcode in bits 26 -- 31
 192   };
 193 
 194   enum opcdxos_masks {
 195     XL_FORM_OPCODE_MASK = (63u << OPCODE_SHIFT) | (1023u << 1),
 196     ADDI_OPCODE_MASK    = (63u << OPCODE_SHIFT),
 197     ADDIS_OPCODE_MASK   = (63u << OPCODE_SHIFT),
 198     BXX_OPCODE_MASK     = (63u << OPCODE_SHIFT),
 199     BCXX_OPCODE_MASK    = (63u << OPCODE_SHIFT),
 200     // trap instructions
 201     TDI_OPCODE_MASK     = (63u << OPCODE_SHIFT),
 202     TWI_OPCODE_MASK     = (63u << OPCODE_SHIFT),
 203     TD_OPCODE_MASK      = (63u << OPCODE_SHIFT) | (1023u << 1),
 204     TW_OPCODE_MASK      = (63u << OPCODE_SHIFT) | (1023u << 1),
 205     LD_OPCODE_MASK      = (63u << OPCODE_SHIFT) | (3u << XO_30_31_SHIFT), // DS-FORM
 206     STD_OPCODE_MASK     = LD_OPCODE_MASK,
 207     STDU_OPCODE_MASK    = STD_OPCODE_MASK,
 208     STDX_OPCODE_MASK    = (63u << OPCODE_SHIFT) | (1023u << 1),
 209     STDUX_OPCODE_MASK   = STDX_OPCODE_MASK,
 210     STW_OPCODE_MASK     = (63u << OPCODE_SHIFT),
 211     STWU_OPCODE_MASK    = STW_OPCODE_MASK,
 212     STWX_OPCODE_MASK    = (63u << OPCODE_SHIFT) | (1023u << 1),
 213     STWUX_OPCODE_MASK   = STWX_OPCODE_MASK,
 214     MTCTR_OPCODE_MASK   = ~(31u << RS_SHIFT),
 215     ORI_OPCODE_MASK     = (63u << OPCODE_SHIFT),
 216     ORIS_OPCODE_MASK    = (63u << OPCODE_SHIFT),
 217     RLDICR_OPCODE_MASK  = (63u << OPCODE_SHIFT) | (7u << XO_27_29_SHIFT)
 218   };
 219 
 220   enum opcdxos {
 221     ADD_OPCODE    = (31u << OPCODE_SHIFT | 266u << 1),
 222     ADDC_OPCODE   = (31u << OPCODE_SHIFT |  10u << 1),
 223     ADDI_OPCODE   = (14u << OPCODE_SHIFT),
 224     ADDIS_OPCODE  = (15u << OPCODE_SHIFT),
 225     ADDIC__OPCODE = (13u << OPCODE_SHIFT),
 226     ADDE_OPCODE   = (31u << OPCODE_SHIFT | 138u << 1),
 227     SUBF_OPCODE   = (31u << OPCODE_SHIFT |  40u << 1),
 228     SUBFC_OPCODE  = (31u << OPCODE_SHIFT |   8u << 1),
 229     SUBFE_OPCODE  = (31u << OPCODE_SHIFT | 136u << 1),
 230     SUBFIC_OPCODE = (8u  << OPCODE_SHIFT),
 231     SUBFZE_OPCODE = (31u << OPCODE_SHIFT | 200u << 1),
 232     DIVW_OPCODE   = (31u << OPCODE_SHIFT | 491u << 1),
 233     MULLW_OPCODE  = (31u << OPCODE_SHIFT | 235u << 1),
 234     MULHW_OPCODE  = (31u << OPCODE_SHIFT |  75u << 1),
 235     MULHWU_OPCODE = (31u << OPCODE_SHIFT |  11u << 1),
 236     MULLI_OPCODE  = (7u  << OPCODE_SHIFT),
 237     AND_OPCODE    = (31u << OPCODE_SHIFT |  28u << 1),
 238     ANDI_OPCODE   = (28u << OPCODE_SHIFT),
 239     ANDIS_OPCODE  = (29u << OPCODE_SHIFT),
 240     ANDC_OPCODE   = (31u << OPCODE_SHIFT |  60u << 1),
 241     ORC_OPCODE    = (31u << OPCODE_SHIFT | 412u << 1),
 242     OR_OPCODE     = (31u << OPCODE_SHIFT | 444u << 1),
 243     ORI_OPCODE    = (24u << OPCODE_SHIFT),
 244     ORIS_OPCODE   = (25u << OPCODE_SHIFT),
 245     XOR_OPCODE    = (31u << OPCODE_SHIFT | 316u << 1),
 246     XORI_OPCODE   = (26u << OPCODE_SHIFT),
 247     XORIS_OPCODE  = (27u << OPCODE_SHIFT),
 248 
 249     NEG_OPCODE    = (31u << OPCODE_SHIFT | 104u << 1),
 250 
 251     RLWINM_OPCODE = (21u << OPCODE_SHIFT),
 252     CLRRWI_OPCODE = RLWINM_OPCODE,
 253     CLRLWI_OPCODE = RLWINM_OPCODE,
 254 
 255     RLWIMI_OPCODE = (20u << OPCODE_SHIFT),
 256 
 257     SLW_OPCODE    = (31u << OPCODE_SHIFT |  24u << 1),
 258     SLWI_OPCODE   = RLWINM_OPCODE,
 259     SRW_OPCODE    = (31u << OPCODE_SHIFT | 536u << 1),
 260     SRWI_OPCODE   = RLWINM_OPCODE,
 261     SRAW_OPCODE   = (31u << OPCODE_SHIFT | 792u << 1),
 262     SRAWI_OPCODE  = (31u << OPCODE_SHIFT | 824u << 1),
 263 
 264     CMP_OPCODE    = (31u << OPCODE_SHIFT |   0u << 1),
 265     CMPI_OPCODE   = (11u << OPCODE_SHIFT),
 266     CMPL_OPCODE   = (31u << OPCODE_SHIFT |  32u << 1),
 267     CMPLI_OPCODE  = (10u << OPCODE_SHIFT),
 268 
 269     ISEL_OPCODE   = (31u << OPCODE_SHIFT |  15u << 1),
 270 
 271     // Special purpose registers
 272     MTSPR_OPCODE  = (31u << OPCODE_SHIFT | 467u << 1),
 273     MFSPR_OPCODE  = (31u << OPCODE_SHIFT | 339u << 1),
 274 
 275     MTXER_OPCODE  = (MTSPR_OPCODE | 1 << SPR_0_4_SHIFT),
 276     MFXER_OPCODE  = (MFSPR_OPCODE | 1 << SPR_0_4_SHIFT),
 277 
 278     MTDSCR_OPCODE = (MTSPR_OPCODE | 3 << SPR_0_4_SHIFT),
 279     MFDSCR_OPCODE = (MFSPR_OPCODE | 3 << SPR_0_4_SHIFT),
 280 
 281     MTLR_OPCODE   = (MTSPR_OPCODE | 8 << SPR_0_4_SHIFT),
 282     MFLR_OPCODE   = (MFSPR_OPCODE | 8 << SPR_0_4_SHIFT),
 283 
 284     MTCTR_OPCODE  = (MTSPR_OPCODE | 9 << SPR_0_4_SHIFT),
 285     MFCTR_OPCODE  = (MFSPR_OPCODE | 9 << SPR_0_4_SHIFT),
 286 
 287     MTTFHAR_OPCODE   = (MTSPR_OPCODE | 128 << SPR_0_4_SHIFT),
 288     MFTFHAR_OPCODE   = (MFSPR_OPCODE | 128 << SPR_0_4_SHIFT),
 289     MTTFIAR_OPCODE   = (MTSPR_OPCODE | 129 << SPR_0_4_SHIFT),
 290     MFTFIAR_OPCODE   = (MFSPR_OPCODE | 129 << SPR_0_4_SHIFT),
 291     MTTEXASR_OPCODE  = (MTSPR_OPCODE | 130 << SPR_0_4_SHIFT),
 292     MFTEXASR_OPCODE  = (MFSPR_OPCODE | 130 << SPR_0_4_SHIFT),
 293     MTTEXASRU_OPCODE = (MTSPR_OPCODE | 131 << SPR_0_4_SHIFT),
 294     MFTEXASRU_OPCODE = (MFSPR_OPCODE | 131 << SPR_0_4_SHIFT),
 295 
 296     MTVRSAVE_OPCODE  = (MTSPR_OPCODE | 256 << SPR_0_4_SHIFT),
 297     MFVRSAVE_OPCODE  = (MFSPR_OPCODE | 256 << SPR_0_4_SHIFT),
 298 
 299     MFTB_OPCODE   = (MFSPR_OPCODE | 268 << SPR_0_4_SHIFT),
 300 
 301     MTCRF_OPCODE  = (31u << OPCODE_SHIFT | 144u << 1),
 302     MFCR_OPCODE   = (31u << OPCODE_SHIFT | 19u << 1),
 303     MCRF_OPCODE   = (19u << OPCODE_SHIFT | 0u << 1),
 304 
 305     // condition register logic instructions
 306     CRAND_OPCODE  = (19u << OPCODE_SHIFT | 257u << 1),
 307     CRNAND_OPCODE = (19u << OPCODE_SHIFT | 225u << 1),
 308     CROR_OPCODE   = (19u << OPCODE_SHIFT | 449u << 1),
 309     CRXOR_OPCODE  = (19u << OPCODE_SHIFT | 193u << 1),
 310     CRNOR_OPCODE  = (19u << OPCODE_SHIFT |  33u << 1),
 311     CREQV_OPCODE  = (19u << OPCODE_SHIFT | 289u << 1),
 312     CRANDC_OPCODE = (19u << OPCODE_SHIFT | 129u << 1),
 313     CRORC_OPCODE  = (19u << OPCODE_SHIFT | 417u << 1),
 314 
 315     BCLR_OPCODE   = (19u << OPCODE_SHIFT | 16u << 1),
 316     BXX_OPCODE      = (18u << OPCODE_SHIFT),
 317     BCXX_OPCODE     = (16u << OPCODE_SHIFT),
 318 
 319     // CTR-related opcodes
 320     BCCTR_OPCODE  = (19u << OPCODE_SHIFT | 528u << 1),
 321 
 322     LWZ_OPCODE   = (32u << OPCODE_SHIFT),
 323     LWZX_OPCODE  = (31u << OPCODE_SHIFT |  23u << 1),
 324     LWZU_OPCODE  = (33u << OPCODE_SHIFT),
 325     LWBRX_OPCODE = (31u << OPCODE_SHIFT |  534 << 1),
 326 
 327     LHA_OPCODE   = (42u << OPCODE_SHIFT),
 328     LHAX_OPCODE  = (31u << OPCODE_SHIFT | 343u << 1),
 329     LHAU_OPCODE  = (43u << OPCODE_SHIFT),
 330 
 331     LHZ_OPCODE   = (40u << OPCODE_SHIFT),
 332     LHZX_OPCODE  = (31u << OPCODE_SHIFT | 279u << 1),
 333     LHZU_OPCODE  = (41u << OPCODE_SHIFT),
 334     LHBRX_OPCODE = (31u << OPCODE_SHIFT |  790 << 1),
 335 
 336     LBZ_OPCODE   = (34u << OPCODE_SHIFT),
 337     LBZX_OPCODE  = (31u << OPCODE_SHIFT |  87u << 1),
 338     LBZU_OPCODE  = (35u << OPCODE_SHIFT),
 339 
 340     STW_OPCODE   = (36u << OPCODE_SHIFT),
 341     STWX_OPCODE  = (31u << OPCODE_SHIFT | 151u << 1),
 342     STWU_OPCODE  = (37u << OPCODE_SHIFT),
 343     STWUX_OPCODE = (31u << OPCODE_SHIFT | 183u << 1),
 344 
 345     STH_OPCODE   = (44u << OPCODE_SHIFT),
 346     STHX_OPCODE  = (31u << OPCODE_SHIFT | 407u << 1),
 347     STHU_OPCODE  = (45u << OPCODE_SHIFT),
 348 
 349     STB_OPCODE   = (38u << OPCODE_SHIFT),
 350     STBX_OPCODE  = (31u << OPCODE_SHIFT | 215u << 1),
 351     STBU_OPCODE  = (39u << OPCODE_SHIFT),
 352 
 353     EXTSB_OPCODE = (31u << OPCODE_SHIFT | 954u << 1),
 354     EXTSH_OPCODE = (31u << OPCODE_SHIFT | 922u << 1),
 355     EXTSW_OPCODE = (31u << OPCODE_SHIFT | 986u << 1),               // X-FORM
 356 
 357     // 32 bit opcode encodings
 358 
 359     LWA_OPCODE    = (58u << OPCODE_SHIFT |   2u << XO_30_31_SHIFT), // DS-FORM
 360     LWAX_OPCODE   = (31u << OPCODE_SHIFT | 341u << XO_21_30_SHIFT), // X-FORM
 361 
 362     CNTLZW_OPCODE = (31u << OPCODE_SHIFT |  26u << XO_21_30_SHIFT), // X-FORM
 363 
 364     // 64 bit opcode encodings
 365 
 366     LD_OPCODE     = (58u << OPCODE_SHIFT |   0u << XO_30_31_SHIFT), // DS-FORM
 367     LDU_OPCODE    = (58u << OPCODE_SHIFT |   1u << XO_30_31_SHIFT), // DS-FORM
 368     LDX_OPCODE    = (31u << OPCODE_SHIFT |  21u << XO_21_30_SHIFT), // X-FORM
 369 
 370     STD_OPCODE    = (62u << OPCODE_SHIFT |   0u << XO_30_31_SHIFT), // DS-FORM
 371     STDU_OPCODE   = (62u << OPCODE_SHIFT |   1u << XO_30_31_SHIFT), // DS-FORM
 372     STDUX_OPCODE  = (31u << OPCODE_SHIFT | 181u << 1),                  // X-FORM
 373     STDX_OPCODE   = (31u << OPCODE_SHIFT | 149u << XO_21_30_SHIFT), // X-FORM
 374 
 375     RLDICR_OPCODE = (30u << OPCODE_SHIFT |   1u << XO_27_29_SHIFT), // MD-FORM
 376     RLDICL_OPCODE = (30u << OPCODE_SHIFT |   0u << XO_27_29_SHIFT), // MD-FORM
 377     RLDIC_OPCODE  = (30u << OPCODE_SHIFT |   2u << XO_27_29_SHIFT), // MD-FORM
 378     RLDIMI_OPCODE = (30u << OPCODE_SHIFT |   3u << XO_27_29_SHIFT), // MD-FORM
 379 
 380     SRADI_OPCODE  = (31u << OPCODE_SHIFT | 413u << XO_21_29_SHIFT), // XS-FORM
 381 
 382     SLD_OPCODE    = (31u << OPCODE_SHIFT |  27u << 1),              // X-FORM
 383     SRD_OPCODE    = (31u << OPCODE_SHIFT | 539u << 1),              // X-FORM
 384     SRAD_OPCODE   = (31u << OPCODE_SHIFT | 794u << 1),              // X-FORM
 385 
 386     MULLD_OPCODE  = (31u << OPCODE_SHIFT | 233u << 1),              // XO-FORM
 387     MULHD_OPCODE  = (31u << OPCODE_SHIFT |  73u << 1),              // XO-FORM
 388     MULHDU_OPCODE = (31u << OPCODE_SHIFT |   9u << 1),              // XO-FORM
 389     DIVD_OPCODE   = (31u << OPCODE_SHIFT | 489u << 1),              // XO-FORM
 390 
 391     CNTLZD_OPCODE = (31u << OPCODE_SHIFT |  58u << XO_21_30_SHIFT), // X-FORM
 392     NAND_OPCODE   = (31u << OPCODE_SHIFT | 476u << XO_21_30_SHIFT), // X-FORM
 393     NOR_OPCODE    = (31u << OPCODE_SHIFT | 124u << XO_21_30_SHIFT), // X-FORM
 394 
 395 
 396     // opcodes only used for floating arithmetic
 397     FADD_OPCODE   = (63u << OPCODE_SHIFT |  21u << 1),
 398     FADDS_OPCODE  = (59u << OPCODE_SHIFT |  21u << 1),
 399     FCMPU_OPCODE  = (63u << OPCODE_SHIFT |  00u << 1),
 400     FDIV_OPCODE   = (63u << OPCODE_SHIFT |  18u << 1),
 401     FDIVS_OPCODE  = (59u << OPCODE_SHIFT |  18u << 1),
 402     FMR_OPCODE    = (63u << OPCODE_SHIFT |  72u << 1),
 403     // These are special Power6 opcodes, reused for "lfdepx" and "stfdepx"
 404     // on Power7.  Do not use.
 405     // MFFGPR_OPCODE  = (31u << OPCODE_SHIFT | 607u << 1),
 406     // MFTGPR_OPCODE  = (31u << OPCODE_SHIFT | 735u << 1),
 407     CMPB_OPCODE    = (31u << OPCODE_SHIFT |  508  << 1),
 408     POPCNTB_OPCODE = (31u << OPCODE_SHIFT |  122  << 1),
 409     POPCNTW_OPCODE = (31u << OPCODE_SHIFT |  378  << 1),
 410     POPCNTD_OPCODE = (31u << OPCODE_SHIFT |  506  << 1),
 411     FABS_OPCODE    = (63u << OPCODE_SHIFT |  264u << 1),
 412     FNABS_OPCODE   = (63u << OPCODE_SHIFT |  136u << 1),
 413     FMUL_OPCODE    = (63u << OPCODE_SHIFT |   25u << 1),
 414     FMULS_OPCODE   = (59u << OPCODE_SHIFT |   25u << 1),
 415     FNEG_OPCODE    = (63u << OPCODE_SHIFT |   40u << 1),
 416     FSUB_OPCODE    = (63u << OPCODE_SHIFT |   20u << 1),
 417     FSUBS_OPCODE   = (59u << OPCODE_SHIFT |   20u << 1),
 418 
 419     // PPC64-internal FPU conversion opcodes
 420     FCFID_OPCODE   = (63u << OPCODE_SHIFT |  846u << 1),
 421     FCFIDS_OPCODE  = (59u << OPCODE_SHIFT |  846u << 1),
 422     FCTID_OPCODE   = (63u << OPCODE_SHIFT |  814u << 1),
 423     FCTIDZ_OPCODE  = (63u << OPCODE_SHIFT |  815u << 1),
 424     FCTIW_OPCODE   = (63u << OPCODE_SHIFT |   14u << 1),
 425     FCTIWZ_OPCODE  = (63u << OPCODE_SHIFT |   15u << 1),
 426     FRSP_OPCODE    = (63u << OPCODE_SHIFT |   12u << 1),
 427 
 428     // WARNING: using fmadd results in a non-compliant vm. Some floating
 429     // point tck tests will fail.
 430     FMADD_OPCODE   = (59u << OPCODE_SHIFT |   29u << 1),
 431     DMADD_OPCODE   = (63u << OPCODE_SHIFT |   29u << 1),
 432     FMSUB_OPCODE   = (59u << OPCODE_SHIFT |   28u << 1),
 433     DMSUB_OPCODE   = (63u << OPCODE_SHIFT |   28u << 1),
 434     FNMADD_OPCODE  = (59u << OPCODE_SHIFT |   31u << 1),
 435     DNMADD_OPCODE  = (63u << OPCODE_SHIFT |   31u << 1),
 436     FNMSUB_OPCODE  = (59u << OPCODE_SHIFT |   30u << 1),
 437     DNMSUB_OPCODE  = (63u << OPCODE_SHIFT |   30u << 1),
 438 
 439     LFD_OPCODE     = (50u << OPCODE_SHIFT |   00u << 1),
 440     LFDU_OPCODE    = (51u << OPCODE_SHIFT |   00u << 1),
 441     LFDX_OPCODE    = (31u << OPCODE_SHIFT |  599u << 1),
 442     LFS_OPCODE     = (48u << OPCODE_SHIFT |   00u << 1),
 443     LFSU_OPCODE    = (49u << OPCODE_SHIFT |   00u << 1),
 444     LFSX_OPCODE    = (31u << OPCODE_SHIFT |  535u << 1),
 445 
 446     STFD_OPCODE    = (54u << OPCODE_SHIFT |   00u << 1),
 447     STFDU_OPCODE   = (55u << OPCODE_SHIFT |   00u << 1),
 448     STFDX_OPCODE   = (31u << OPCODE_SHIFT |  727u << 1),
 449     STFS_OPCODE    = (52u << OPCODE_SHIFT |   00u << 1),
 450     STFSU_OPCODE   = (53u << OPCODE_SHIFT |   00u << 1),
 451     STFSX_OPCODE   = (31u << OPCODE_SHIFT |  663u << 1),
 452 
 453     FSQRT_OPCODE   = (63u << OPCODE_SHIFT |   22u << 1),            // A-FORM
 454     FSQRTS_OPCODE  = (59u << OPCODE_SHIFT |   22u << 1),            // A-FORM
 455 
 456     // Vector instruction support for >= Power6
 457     // Vector Storage Access
 458     LVEBX_OPCODE   = (31u << OPCODE_SHIFT |    7u << 1),
 459     LVEHX_OPCODE   = (31u << OPCODE_SHIFT |   39u << 1),
 460     LVEWX_OPCODE   = (31u << OPCODE_SHIFT |   71u << 1),
 461     LVX_OPCODE     = (31u << OPCODE_SHIFT |  103u << 1),
 462     LVXL_OPCODE    = (31u << OPCODE_SHIFT |  359u << 1),
 463     STVEBX_OPCODE  = (31u << OPCODE_SHIFT |  135u << 1),
 464     STVEHX_OPCODE  = (31u << OPCODE_SHIFT |  167u << 1),
 465     STVEWX_OPCODE  = (31u << OPCODE_SHIFT |  199u << 1),
 466     STVX_OPCODE    = (31u << OPCODE_SHIFT |  231u << 1),
 467     STVXL_OPCODE   = (31u << OPCODE_SHIFT |  487u << 1),
 468     LVSL_OPCODE    = (31u << OPCODE_SHIFT |    6u << 1),
 469     LVSR_OPCODE    = (31u << OPCODE_SHIFT |   38u << 1),
 470 
 471     // Vector-Scalar (VSX) instruction support.
 472     LXVD2X_OPCODE  = (31u << OPCODE_SHIFT |  844u << 1),
 473     STXVD2X_OPCODE = (31u << OPCODE_SHIFT |  972u << 1),
 474     MTVSRD_OPCODE  = (31u << OPCODE_SHIFT |  179u << 1),
 475     MFVSRD_OPCODE  = (31u << OPCODE_SHIFT |   51u << 1),
 476 
 477     // Vector Permute and Formatting
 478     VPKPX_OPCODE   = (4u  << OPCODE_SHIFT |  782u     ),
 479     VPKSHSS_OPCODE = (4u  << OPCODE_SHIFT |  398u     ),
 480     VPKSWSS_OPCODE = (4u  << OPCODE_SHIFT |  462u     ),
 481     VPKSHUS_OPCODE = (4u  << OPCODE_SHIFT |  270u     ),
 482     VPKSWUS_OPCODE = (4u  << OPCODE_SHIFT |  334u     ),
 483     VPKUHUM_OPCODE = (4u  << OPCODE_SHIFT |   14u     ),
 484     VPKUWUM_OPCODE = (4u  << OPCODE_SHIFT |   78u     ),
 485     VPKUHUS_OPCODE = (4u  << OPCODE_SHIFT |  142u     ),
 486     VPKUWUS_OPCODE = (4u  << OPCODE_SHIFT |  206u     ),
 487     VUPKHPX_OPCODE = (4u  << OPCODE_SHIFT |  846u     ),
 488     VUPKHSB_OPCODE = (4u  << OPCODE_SHIFT |  526u     ),
 489     VUPKHSH_OPCODE = (4u  << OPCODE_SHIFT |  590u     ),
 490     VUPKLPX_OPCODE = (4u  << OPCODE_SHIFT |  974u     ),
 491     VUPKLSB_OPCODE = (4u  << OPCODE_SHIFT |  654u     ),
 492     VUPKLSH_OPCODE = (4u  << OPCODE_SHIFT |  718u     ),
 493 
 494     VMRGHB_OPCODE  = (4u  << OPCODE_SHIFT |   12u     ),
 495     VMRGHW_OPCODE  = (4u  << OPCODE_SHIFT |  140u     ),
 496     VMRGHH_OPCODE  = (4u  << OPCODE_SHIFT |   76u     ),
 497     VMRGLB_OPCODE  = (4u  << OPCODE_SHIFT |  268u     ),
 498     VMRGLW_OPCODE  = (4u  << OPCODE_SHIFT |  396u     ),
 499     VMRGLH_OPCODE  = (4u  << OPCODE_SHIFT |  332u     ),
 500 
 501     VSPLT_OPCODE   = (4u  << OPCODE_SHIFT |  524u     ),
 502     VSPLTH_OPCODE  = (4u  << OPCODE_SHIFT |  588u     ),
 503     VSPLTW_OPCODE  = (4u  << OPCODE_SHIFT |  652u     ),
 504     VSPLTISB_OPCODE= (4u  << OPCODE_SHIFT |  780u     ),
 505     VSPLTISH_OPCODE= (4u  << OPCODE_SHIFT |  844u     ),
 506     VSPLTISW_OPCODE= (4u  << OPCODE_SHIFT |  908u     ),
 507 
 508     VPERM_OPCODE   = (4u  << OPCODE_SHIFT |   43u     ),
 509     VSEL_OPCODE    = (4u  << OPCODE_SHIFT |   42u     ),
 510 
 511     VSL_OPCODE     = (4u  << OPCODE_SHIFT |  452u     ),
 512     VSLDOI_OPCODE  = (4u  << OPCODE_SHIFT |   44u     ),
 513     VSLO_OPCODE    = (4u  << OPCODE_SHIFT | 1036u     ),
 514     VSR_OPCODE     = (4u  << OPCODE_SHIFT |  708u     ),
 515     VSRO_OPCODE    = (4u  << OPCODE_SHIFT | 1100u     ),
 516 
 517     // Vector Integer
 518     VADDCUW_OPCODE = (4u  << OPCODE_SHIFT |  384u     ),
 519     VADDSHS_OPCODE = (4u  << OPCODE_SHIFT |  832u     ),
 520     VADDSBS_OPCODE = (4u  << OPCODE_SHIFT |  768u     ),
 521     VADDSWS_OPCODE = (4u  << OPCODE_SHIFT |  896u     ),
 522     VADDUBM_OPCODE = (4u  << OPCODE_SHIFT |    0u     ),
 523     VADDUWM_OPCODE = (4u  << OPCODE_SHIFT |  128u     ),
 524     VADDUHM_OPCODE = (4u  << OPCODE_SHIFT |   64u     ),
 525     VADDUBS_OPCODE = (4u  << OPCODE_SHIFT |  512u     ),
 526     VADDUWS_OPCODE = (4u  << OPCODE_SHIFT |  640u     ),
 527     VADDUHS_OPCODE = (4u  << OPCODE_SHIFT |  576u     ),
 528     VSUBCUW_OPCODE = (4u  << OPCODE_SHIFT | 1408u     ),
 529     VSUBSHS_OPCODE = (4u  << OPCODE_SHIFT | 1856u     ),
 530     VSUBSBS_OPCODE = (4u  << OPCODE_SHIFT | 1792u     ),
 531     VSUBSWS_OPCODE = (4u  << OPCODE_SHIFT | 1920u     ),
 532     VSUBUBM_OPCODE = (4u  << OPCODE_SHIFT | 1024u     ),
 533     VSUBUWM_OPCODE = (4u  << OPCODE_SHIFT | 1152u     ),
 534     VSUBUHM_OPCODE = (4u  << OPCODE_SHIFT | 1088u     ),
 535     VSUBUBS_OPCODE = (4u  << OPCODE_SHIFT | 1536u     ),
 536     VSUBUWS_OPCODE = (4u  << OPCODE_SHIFT | 1664u     ),
 537     VSUBUHS_OPCODE = (4u  << OPCODE_SHIFT | 1600u     ),
 538 
 539     VMULESB_OPCODE = (4u  << OPCODE_SHIFT |  776u     ),
 540     VMULEUB_OPCODE = (4u  << OPCODE_SHIFT |  520u     ),
 541     VMULESH_OPCODE = (4u  << OPCODE_SHIFT |  840u     ),
 542     VMULEUH_OPCODE = (4u  << OPCODE_SHIFT |  584u     ),
 543     VMULOSB_OPCODE = (4u  << OPCODE_SHIFT |  264u     ),
 544     VMULOUB_OPCODE = (4u  << OPCODE_SHIFT |    8u     ),
 545     VMULOSH_OPCODE = (4u  << OPCODE_SHIFT |  328u     ),
 546     VMULOUH_OPCODE = (4u  << OPCODE_SHIFT |   72u     ),
 547     VMHADDSHS_OPCODE=(4u  << OPCODE_SHIFT |   32u     ),
 548     VMHRADDSHS_OPCODE=(4u << OPCODE_SHIFT |   33u     ),
 549     VMLADDUHM_OPCODE=(4u  << OPCODE_SHIFT |   34u     ),
 550     VMSUBUHM_OPCODE= (4u  << OPCODE_SHIFT |   36u     ),
 551     VMSUMMBM_OPCODE= (4u  << OPCODE_SHIFT |   37u     ),
 552     VMSUMSHM_OPCODE= (4u  << OPCODE_SHIFT |   40u     ),
 553     VMSUMSHS_OPCODE= (4u  << OPCODE_SHIFT |   41u     ),
 554     VMSUMUHM_OPCODE= (4u  << OPCODE_SHIFT |   38u     ),
 555     VMSUMUHS_OPCODE= (4u  << OPCODE_SHIFT |   39u     ),
 556 
 557     VSUMSWS_OPCODE = (4u  << OPCODE_SHIFT | 1928u     ),
 558     VSUM2SWS_OPCODE= (4u  << OPCODE_SHIFT | 1672u     ),
 559     VSUM4SBS_OPCODE= (4u  << OPCODE_SHIFT | 1800u     ),
 560     VSUM4UBS_OPCODE= (4u  << OPCODE_SHIFT | 1544u     ),
 561     VSUM4SHS_OPCODE= (4u  << OPCODE_SHIFT | 1608u     ),
 562 
 563     VAVGSB_OPCODE  = (4u  << OPCODE_SHIFT | 1282u     ),
 564     VAVGSW_OPCODE  = (4u  << OPCODE_SHIFT | 1410u     ),
 565     VAVGSH_OPCODE  = (4u  << OPCODE_SHIFT | 1346u     ),
 566     VAVGUB_OPCODE  = (4u  << OPCODE_SHIFT | 1026u     ),
 567     VAVGUW_OPCODE  = (4u  << OPCODE_SHIFT | 1154u     ),
 568     VAVGUH_OPCODE  = (4u  << OPCODE_SHIFT | 1090u     ),
 569 
 570     VMAXSB_OPCODE  = (4u  << OPCODE_SHIFT |  258u     ),
 571     VMAXSW_OPCODE  = (4u  << OPCODE_SHIFT |  386u     ),
 572     VMAXSH_OPCODE  = (4u  << OPCODE_SHIFT |  322u     ),
 573     VMAXUB_OPCODE  = (4u  << OPCODE_SHIFT |    2u     ),
 574     VMAXUW_OPCODE  = (4u  << OPCODE_SHIFT |  130u     ),
 575     VMAXUH_OPCODE  = (4u  << OPCODE_SHIFT |   66u     ),
 576     VMINSB_OPCODE  = (4u  << OPCODE_SHIFT |  770u     ),
 577     VMINSW_OPCODE  = (4u  << OPCODE_SHIFT |  898u     ),
 578     VMINSH_OPCODE  = (4u  << OPCODE_SHIFT |  834u     ),
 579     VMINUB_OPCODE  = (4u  << OPCODE_SHIFT |  514u     ),
 580     VMINUW_OPCODE  = (4u  << OPCODE_SHIFT |  642u     ),
 581     VMINUH_OPCODE  = (4u  << OPCODE_SHIFT |  578u     ),
 582 
 583     VCMPEQUB_OPCODE= (4u  << OPCODE_SHIFT |    6u     ),
 584     VCMPEQUH_OPCODE= (4u  << OPCODE_SHIFT |   70u     ),
 585     VCMPEQUW_OPCODE= (4u  << OPCODE_SHIFT |  134u     ),
 586     VCMPGTSH_OPCODE= (4u  << OPCODE_SHIFT |  838u     ),
 587     VCMPGTSB_OPCODE= (4u  << OPCODE_SHIFT |  774u     ),
 588     VCMPGTSW_OPCODE= (4u  << OPCODE_SHIFT |  902u     ),
 589     VCMPGTUB_OPCODE= (4u  << OPCODE_SHIFT |  518u     ),
 590     VCMPGTUH_OPCODE= (4u  << OPCODE_SHIFT |  582u     ),
 591     VCMPGTUW_OPCODE= (4u  << OPCODE_SHIFT |  646u     ),
 592 
 593     VAND_OPCODE    = (4u  << OPCODE_SHIFT | 1028u     ),
 594     VANDC_OPCODE   = (4u  << OPCODE_SHIFT | 1092u     ),
 595     VNOR_OPCODE    = (4u  << OPCODE_SHIFT | 1284u     ),
 596     VOR_OPCODE     = (4u  << OPCODE_SHIFT | 1156u     ),
 597     VXOR_OPCODE    = (4u  << OPCODE_SHIFT | 1220u     ),
 598     VRLD_OPCODE    = (4u  << OPCODE_SHIFT |  196u     ),
 599     VRLB_OPCODE    = (4u  << OPCODE_SHIFT |    4u     ),
 600     VRLW_OPCODE    = (4u  << OPCODE_SHIFT |  132u     ),
 601     VRLH_OPCODE    = (4u  << OPCODE_SHIFT |   68u     ),
 602     VSLB_OPCODE    = (4u  << OPCODE_SHIFT |  260u     ),
 603     VSKW_OPCODE    = (4u  << OPCODE_SHIFT |  388u     ),
 604     VSLH_OPCODE    = (4u  << OPCODE_SHIFT |  324u     ),
 605     VSRB_OPCODE    = (4u  << OPCODE_SHIFT |  516u     ),
 606     VSRW_OPCODE    = (4u  << OPCODE_SHIFT |  644u     ),
 607     VSRH_OPCODE    = (4u  << OPCODE_SHIFT |  580u     ),
 608     VSRAB_OPCODE   = (4u  << OPCODE_SHIFT |  772u     ),
 609     VSRAW_OPCODE   = (4u  << OPCODE_SHIFT |  900u     ),
 610     VSRAH_OPCODE   = (4u  << OPCODE_SHIFT |  836u     ),
 611 
 612     // Vector Floating-Point
 613     // not implemented yet
 614 
 615     // Vector Status and Control
 616     MTVSCR_OPCODE  = (4u  << OPCODE_SHIFT | 1604u     ),
 617     MFVSCR_OPCODE  = (4u  << OPCODE_SHIFT | 1540u     ),
 618 
 619     // AES (introduced with Power 8)
 620     VCIPHER_OPCODE      = (4u  << OPCODE_SHIFT | 1288u),
 621     VCIPHERLAST_OPCODE  = (4u  << OPCODE_SHIFT | 1289u),
 622     VNCIPHER_OPCODE     = (4u  << OPCODE_SHIFT | 1352u),
 623     VNCIPHERLAST_OPCODE = (4u  << OPCODE_SHIFT | 1353u),
 624     VSBOX_OPCODE        = (4u  << OPCODE_SHIFT | 1480u),
 625 
 626     // SHA (introduced with Power 8)
 627     VSHASIGMAD_OPCODE   = (4u  << OPCODE_SHIFT | 1730u),
 628     VSHASIGMAW_OPCODE   = (4u  << OPCODE_SHIFT | 1666u),
 629 
 630     // Vector Binary Polynomial Multiplication (introduced with Power 8)
 631     VPMSUMB_OPCODE      = (4u  << OPCODE_SHIFT | 1032u),
 632     VPMSUMD_OPCODE      = (4u  << OPCODE_SHIFT | 1224u),
 633     VPMSUMH_OPCODE      = (4u  << OPCODE_SHIFT | 1096u),
 634     VPMSUMW_OPCODE      = (4u  << OPCODE_SHIFT | 1160u),
 635 
 636     // Vector Permute and Xor (introduced with Power 8)
 637     VPERMXOR_OPCODE     = (4u  << OPCODE_SHIFT |   45u),
 638 
 639     // Transactional Memory instructions (introduced with Power 8)
 640     TBEGIN_OPCODE    = (31u << OPCODE_SHIFT |  654u << 1),
 641     TEND_OPCODE      = (31u << OPCODE_SHIFT |  686u << 1),
 642     TABORT_OPCODE    = (31u << OPCODE_SHIFT |  910u << 1),
 643     TABORTWC_OPCODE  = (31u << OPCODE_SHIFT |  782u << 1),
 644     TABORTWCI_OPCODE = (31u << OPCODE_SHIFT |  846u << 1),
 645     TABORTDC_OPCODE  = (31u << OPCODE_SHIFT |  814u << 1),
 646     TABORTDCI_OPCODE = (31u << OPCODE_SHIFT |  878u << 1),
 647     TSR_OPCODE       = (31u << OPCODE_SHIFT |  750u << 1),
 648     TCHECK_OPCODE    = (31u << OPCODE_SHIFT |  718u << 1),
 649 
 650     // Icache and dcache related instructions
 651     DCBA_OPCODE    = (31u << OPCODE_SHIFT |  758u << 1),
 652     DCBZ_OPCODE    = (31u << OPCODE_SHIFT | 1014u << 1),
 653     DCBST_OPCODE   = (31u << OPCODE_SHIFT |   54u << 1),
 654     DCBF_OPCODE    = (31u << OPCODE_SHIFT |   86u << 1),
 655 
 656     DCBT_OPCODE    = (31u << OPCODE_SHIFT |  278u << 1),
 657     DCBTST_OPCODE  = (31u << OPCODE_SHIFT |  246u << 1),
 658     ICBI_OPCODE    = (31u << OPCODE_SHIFT |  982u << 1),
 659 
 660     // Instruction synchronization
 661     ISYNC_OPCODE   = (19u << OPCODE_SHIFT |  150u << 1),
 662     // Memory barriers
 663     SYNC_OPCODE    = (31u << OPCODE_SHIFT |  598u << 1),
 664     EIEIO_OPCODE   = (31u << OPCODE_SHIFT |  854u << 1),
 665 
 666     // Trap instructions
 667     TDI_OPCODE     = (2u  << OPCODE_SHIFT),
 668     TWI_OPCODE     = (3u  << OPCODE_SHIFT),
 669     TD_OPCODE      = (31u << OPCODE_SHIFT |   68u << 1),
 670     TW_OPCODE      = (31u << OPCODE_SHIFT |    4u << 1),
 671 
 672     // Atomics.
 673     LWARX_OPCODE   = (31u << OPCODE_SHIFT |   20u << 1),
 674     LDARX_OPCODE   = (31u << OPCODE_SHIFT |   84u << 1),
 675     LQARX_OPCODE   = (31u << OPCODE_SHIFT |  276u << 1),
 676     STWCX_OPCODE   = (31u << OPCODE_SHIFT |  150u << 1),
 677     STDCX_OPCODE   = (31u << OPCODE_SHIFT |  214u << 1),
 678     STQCX_OPCODE   = (31u << OPCODE_SHIFT |  182u << 1)
 679 
 680   };
 681 
 682   // Trap instructions TO bits
 683   enum trap_to_bits {
 684     // single bits
 685     traptoLessThanSigned      = 1 << 4, // 0, left end
 686     traptoGreaterThanSigned   = 1 << 3,
 687     traptoEqual               = 1 << 2,
 688     traptoLessThanUnsigned    = 1 << 1,
 689     traptoGreaterThanUnsigned = 1 << 0, // 4, right end
 690 
 691     // compound ones
 692     traptoUnconditional       = (traptoLessThanSigned |
 693                                  traptoGreaterThanSigned |
 694                                  traptoEqual |
 695                                  traptoLessThanUnsigned |
 696                                  traptoGreaterThanUnsigned)
 697   };
 698 
 699   // Branch hints BH field
 700   enum branch_hint_bh {
 701     // bclr cases:
 702     bhintbhBCLRisReturn            = 0,
 703     bhintbhBCLRisNotReturnButSame  = 1,
 704     bhintbhBCLRisNotPredictable    = 3,
 705 
 706     // bcctr cases:
 707     bhintbhBCCTRisNotReturnButSame = 0,
 708     bhintbhBCCTRisNotPredictable   = 3
 709   };
 710 
 711   // Branch prediction hints AT field
 712   enum branch_hint_at {
 713     bhintatNoHint     = 0,  // at=00
 714     bhintatIsNotTaken = 2,  // at=10
 715     bhintatIsTaken    = 3   // at=11
 716   };
 717 
 718   // Branch prediction hints
 719   enum branch_hint_concept {
 720     // Use the same encoding as branch_hint_at to simply code.
 721     bhintNoHint       = bhintatNoHint,
 722     bhintIsNotTaken   = bhintatIsNotTaken,
 723     bhintIsTaken      = bhintatIsTaken
 724   };
 725 
 726   // Used in BO field of branch instruction.
 727   enum branch_condition {
 728     bcondCRbiIs0      =  4, // bo=001at
 729     bcondCRbiIs1      = 12, // bo=011at
 730     bcondAlways       = 20  // bo=10100
 731   };
 732 
 733   // Branch condition with combined prediction hints.
 734   enum branch_condition_with_hint {
 735     bcondCRbiIs0_bhintNoHint     = bcondCRbiIs0 | bhintatNoHint,
 736     bcondCRbiIs0_bhintIsNotTaken = bcondCRbiIs0 | bhintatIsNotTaken,
 737     bcondCRbiIs0_bhintIsTaken    = bcondCRbiIs0 | bhintatIsTaken,
 738     bcondCRbiIs1_bhintNoHint     = bcondCRbiIs1 | bhintatNoHint,
 739     bcondCRbiIs1_bhintIsNotTaken = bcondCRbiIs1 | bhintatIsNotTaken,
 740     bcondCRbiIs1_bhintIsTaken    = bcondCRbiIs1 | bhintatIsTaken,
 741   };
 742 
 743   // Elemental Memory Barriers (>=Power 8)
 744   enum Elemental_Membar_mask_bits {
 745     StoreStore = 1 << 0,
 746     StoreLoad  = 1 << 1,
 747     LoadStore  = 1 << 2,
 748     LoadLoad   = 1 << 3
 749   };
 750 
 751   // Branch prediction hints.
 752   inline static int add_bhint_to_boint(const int bhint, const int boint) {
 753     switch (boint) {
 754       case bcondCRbiIs0:
 755       case bcondCRbiIs1:
 756         // branch_hint and branch_hint_at have same encodings
 757         assert(   (int)bhintNoHint     == (int)bhintatNoHint
 758                && (int)bhintIsNotTaken == (int)bhintatIsNotTaken
 759                && (int)bhintIsTaken    == (int)bhintatIsTaken,
 760                "wrong encodings");
 761         assert((bhint & 0x03) == bhint, "wrong encodings");
 762         return (boint & ~0x03) | bhint;
 763       case bcondAlways:
 764         // no branch_hint
 765         return boint;
 766       default:
 767         ShouldNotReachHere();
 768         return 0;
 769     }
 770   }
 771 
 772   // Extract bcond from boint.
 773   inline static int inv_boint_bcond(const int boint) {
 774     int r_bcond = boint & ~0x03;
 775     assert(r_bcond == bcondCRbiIs0 ||
 776            r_bcond == bcondCRbiIs1 ||
 777            r_bcond == bcondAlways,
 778            "bad branch condition");
 779     return r_bcond;
 780   }
 781 
 782   // Extract bhint from boint.
 783   inline static int inv_boint_bhint(const int boint) {
 784     int r_bhint = boint & 0x03;
 785     assert(r_bhint == bhintatNoHint ||
 786            r_bhint == bhintatIsNotTaken ||
 787            r_bhint == bhintatIsTaken,
 788            "bad branch hint");
 789     return r_bhint;
 790   }
 791 
 792   // Calculate opposite of given bcond.
 793   inline static int opposite_bcond(const int bcond) {
 794     switch (bcond) {
 795       case bcondCRbiIs0:
 796         return bcondCRbiIs1;
 797       case bcondCRbiIs1:
 798         return bcondCRbiIs0;
 799       default:
 800         ShouldNotReachHere();
 801         return 0;
 802     }
 803   }
 804 
 805   // Calculate opposite of given bhint.
 806   inline static int opposite_bhint(const int bhint) {
 807     switch (bhint) {
 808       case bhintatNoHint:
 809         return bhintatNoHint;
 810       case bhintatIsNotTaken:
 811         return bhintatIsTaken;
 812       case bhintatIsTaken:
 813         return bhintatIsNotTaken;
 814       default:
 815         ShouldNotReachHere();
 816         return 0;
 817     }
 818   }
 819 
 820   // PPC branch instructions
 821   enum ppcops {
 822     b_op    = 18,
 823     bc_op   = 16,
 824     bcr_op  = 19
 825   };
 826 
 827   enum Condition {
 828     negative         = 0,
 829     less             = 0,
 830     positive         = 1,
 831     greater          = 1,
 832     zero             = 2,
 833     equal            = 2,
 834     summary_overflow = 3,
 835   };
 836 
 837  public:
 838   // Helper functions for groups of instructions
 839 
 840   enum Predict { pt = 1, pn = 0 }; // pt = predict taken
 841 
 842   // instruction must start at passed address
 843   static int instr_len(unsigned char *instr) { return BytesPerInstWord; }
 844 
 845   // instruction must be left-justified in argument
 846   static int instr_len(unsigned long instr)  { return BytesPerInstWord; }
 847 
 848   // longest instructions
 849   static int instr_maxlen() { return BytesPerInstWord; }
 850 
 851   // Test if x is within signed immediate range for nbits.
 852   static bool is_simm(int x, unsigned int nbits) {
 853     assert(0 < nbits && nbits < 32, "out of bounds");
 854     const int   min      = -( ((int)1) << nbits-1 );
 855     const int   maxplus1 =  ( ((int)1) << nbits-1 );
 856     return min <= x && x < maxplus1;
 857   }
 858 
 859   static bool is_simm(jlong x, unsigned int nbits) {
 860     assert(0 < nbits && nbits < 64, "out of bounds");
 861     const jlong min      = -( ((jlong)1) << nbits-1 );
 862     const jlong maxplus1 =  ( ((jlong)1) << nbits-1 );
 863     return min <= x && x < maxplus1;
 864   }
 865 
 866   // Test if x is within unsigned immediate range for nbits
 867   static bool is_uimm(int x, unsigned int nbits) {
 868     assert(0 < nbits && nbits < 32, "out of bounds");
 869     const int   maxplus1 = ( ((int)1) << nbits );
 870     return 0 <= x && x < maxplus1;
 871   }
 872 
 873   static bool is_uimm(jlong x, unsigned int nbits) {
 874     assert(0 < nbits && nbits < 64, "out of bounds");
 875     const jlong maxplus1 =  ( ((jlong)1) << nbits );
 876     return 0 <= x && x < maxplus1;
 877   }
 878 
 879  protected:
 880   // helpers
 881 
 882   // X is supposed to fit in a field "nbits" wide
 883   // and be sign-extended. Check the range.
 884   static void assert_signed_range(intptr_t x, int nbits) {
 885     assert(nbits == 32 || (-(1 << nbits-1) <= x && x < (1 << nbits-1)),
 886            "value out of range");
 887   }
 888 
 889   static void assert_signed_word_disp_range(intptr_t x, int nbits) {
 890     assert((x & 3) == 0, "not word aligned");
 891     assert_signed_range(x, nbits + 2);
 892   }
 893 
 894   static void assert_unsigned_const(int x, int nbits) {
 895     assert(juint(x) < juint(1 << nbits), "unsigned constant out of range");
 896   }
 897 
 898   static int fmask(juint hi_bit, juint lo_bit) {
 899     assert(hi_bit >= lo_bit && hi_bit < 32, "bad bits");
 900     return (1 << ( hi_bit-lo_bit + 1 )) - 1;
 901   }
 902 
 903   // inverse of u_field
 904   static int inv_u_field(int x, int hi_bit, int lo_bit) {
 905     juint r = juint(x) >> lo_bit;
 906     r &= fmask(hi_bit, lo_bit);
 907     return int(r);
 908   }
 909 
 910   // signed version: extract from field and sign-extend
 911   static int inv_s_field_ppc(int x, int hi_bit, int lo_bit) {
 912     x = x << (31-hi_bit);
 913     x = x >> (31-hi_bit+lo_bit);
 914     return x;
 915   }
 916 
 917   static int u_field(int x, int hi_bit, int lo_bit) {
 918     assert((x & ~fmask(hi_bit, lo_bit)) == 0, "value out of range");
 919     int r = x << lo_bit;
 920     assert(inv_u_field(r, hi_bit, lo_bit) == x, "just checking");
 921     return r;
 922   }
 923 
 924   // Same as u_field for signed values
 925   static int s_field(int x, int hi_bit, int lo_bit) {
 926     int nbits = hi_bit - lo_bit + 1;
 927     assert(nbits == 32 || (-(1 << nbits-1) <= x && x < (1 << nbits-1)),
 928       "value out of range");
 929     x &= fmask(hi_bit, lo_bit);
 930     int r = x << lo_bit;
 931     return r;
 932   }
 933 
 934   // inv_op for ppc instructions
 935   static int inv_op_ppc(int x) { return inv_u_field(x, 31, 26); }
 936 
 937   // Determine target address from li, bd field of branch instruction.
 938   static intptr_t inv_li_field(int x) {
 939     intptr_t r = inv_s_field_ppc(x, 25, 2);
 940     r = (r << 2);
 941     return r;
 942   }
 943   static intptr_t inv_bd_field(int x, intptr_t pos) {
 944     intptr_t r = inv_s_field_ppc(x, 15, 2);
 945     r = (r << 2) + pos;
 946     return r;
 947   }
 948 
 949   #define inv_opp_u_field(x, hi_bit, lo_bit) inv_u_field(x, 31-(lo_bit), 31-(hi_bit))
 950   #define inv_opp_s_field(x, hi_bit, lo_bit) inv_s_field_ppc(x, 31-(lo_bit), 31-(hi_bit))
 951   // Extract instruction fields from instruction words.
 952  public:
 953   static int inv_ra_field(int x)  { return inv_opp_u_field(x, 15, 11); }
 954   static int inv_rb_field(int x)  { return inv_opp_u_field(x, 20, 16); }
 955   static int inv_rt_field(int x)  { return inv_opp_u_field(x, 10,  6); }
 956   static int inv_rta_field(int x) { return inv_opp_u_field(x, 15, 11); }
 957   static int inv_rs_field(int x)  { return inv_opp_u_field(x, 10,  6); }
 958   // Ds uses opp_s_field(x, 31, 16), but lowest 2 bits must be 0.
 959   // Inv_ds_field uses range (x, 29, 16) but shifts by 2 to ensure that lowest bits are 0.
 960   static int inv_ds_field(int x)  { return inv_opp_s_field(x, 29, 16) << 2; }
 961   static int inv_d1_field(int x)  { return inv_opp_s_field(x, 31, 16); }
 962   static int inv_si_field(int x)  { return inv_opp_s_field(x, 31, 16); }
 963   static int inv_to_field(int x)  { return inv_opp_u_field(x, 10, 6);  }
 964   static int inv_lk_field(int x)  { return inv_opp_u_field(x, 31, 31); }
 965   static int inv_bo_field(int x)  { return inv_opp_u_field(x, 10,  6); }
 966   static int inv_bi_field(int x)  { return inv_opp_u_field(x, 15, 11); }
 967 
 968   #define opp_u_field(x, hi_bit, lo_bit) u_field(x, 31-(lo_bit), 31-(hi_bit))
 969   #define opp_s_field(x, hi_bit, lo_bit) s_field(x, 31-(lo_bit), 31-(hi_bit))
 970 
 971   // instruction fields
 972   static int aa(       int         x)  { return  opp_u_field(x,             30, 30); }
 973   static int ba(       int         x)  { return  opp_u_field(x,             15, 11); }
 974   static int bb(       int         x)  { return  opp_u_field(x,             20, 16); }
 975   static int bc(       int         x)  { return  opp_u_field(x,             25, 21); }
 976   static int bd(       int         x)  { return  opp_s_field(x,             29, 16); }
 977   static int bf( ConditionRegister cr) { return  bf(cr->encoding()); }
 978   static int bf(       int         x)  { return  opp_u_field(x,              8,  6); }
 979   static int bfa(ConditionRegister cr) { return  bfa(cr->encoding()); }
 980   static int bfa(      int         x)  { return  opp_u_field(x,             13, 11); }
 981   static int bh(       int         x)  { return  opp_u_field(x,             20, 19); }
 982   static int bi(       int         x)  { return  opp_u_field(x,             15, 11); }
 983   static int bi0(ConditionRegister cr, Condition c) { return (cr->encoding() << 2) | c; }
 984   static int bo(       int         x)  { return  opp_u_field(x,             10,  6); }
 985   static int bt(       int         x)  { return  opp_u_field(x,             10,  6); }
 986   static int d1(       int         x)  { return  opp_s_field(x,             31, 16); }
 987   static int ds(       int         x)  { assert((x & 0x3) == 0, "unaligned offset"); return opp_s_field(x, 31, 16); }
 988   static int eh(       int         x)  { return  opp_u_field(x,             31, 31); }
 989   static int flm(      int         x)  { return  opp_u_field(x,             14,  7); }
 990   static int fra(    FloatRegister r)  { return  fra(r->encoding());}
 991   static int frb(    FloatRegister r)  { return  frb(r->encoding());}
 992   static int frc(    FloatRegister r)  { return  frc(r->encoding());}
 993   static int frs(    FloatRegister r)  { return  frs(r->encoding());}
 994   static int frt(    FloatRegister r)  { return  frt(r->encoding());}
 995   static int fra(      int         x)  { return  opp_u_field(x,             15, 11); }
 996   static int frb(      int         x)  { return  opp_u_field(x,             20, 16); }
 997   static int frc(      int         x)  { return  opp_u_field(x,             25, 21); }
 998   static int frs(      int         x)  { return  opp_u_field(x,             10,  6); }
 999   static int frt(      int         x)  { return  opp_u_field(x,             10,  6); }
1000   static int fxm(      int         x)  { return  opp_u_field(x,             19, 12); }
1001   static int l10(      int         x)  { return  opp_u_field(x,             10, 10); }
1002   static int l15(      int         x)  { return  opp_u_field(x,             15, 15); }
1003   static int l910(     int         x)  { return  opp_u_field(x,             10,  9); }
1004   static int e1215(    int         x)  { return  opp_u_field(x,             15, 12); }
1005   static int lev(      int         x)  { return  opp_u_field(x,             26, 20); }
1006   static int li(       int         x)  { return  opp_s_field(x,             29,  6); }
1007   static int lk(       int         x)  { return  opp_u_field(x,             31, 31); }
1008   static int mb2125(   int         x)  { return  opp_u_field(x,             25, 21); }
1009   static int me2630(   int         x)  { return  opp_u_field(x,             30, 26); }
1010   static int mb2126(   int         x)  { return  opp_u_field(((x & 0x1f) << 1) | ((x & 0x20) >> 5), 26, 21); }
1011   static int me2126(   int         x)  { return  mb2126(x); }
1012   static int nb(       int         x)  { return  opp_u_field(x,             20, 16); }
1013   //static int opcd(   int         x)  { return  opp_u_field(x,              5,  0); } // is contained in our opcodes
1014   static int oe(       int         x)  { return  opp_u_field(x,             21, 21); }
1015   static int ra(       Register    r)  { return  ra(r->encoding()); }
1016   static int ra(       int         x)  { return  opp_u_field(x,             15, 11); }
1017   static int rb(       Register    r)  { return  rb(r->encoding()); }
1018   static int rb(       int         x)  { return  opp_u_field(x,             20, 16); }
1019   static int rc(       int         x)  { return  opp_u_field(x,             31, 31); }
1020   static int rs(       Register    r)  { return  rs(r->encoding()); }
1021   static int rs(       int         x)  { return  opp_u_field(x,             10,  6); }
1022   // we don't want to use R0 in memory accesses, because it has value `0' then
1023   static int ra0mem(   Register    r)  { assert(r != R0, "cannot use register R0 in memory access"); return ra(r); }
1024   static int ra0mem(   int         x)  { assert(x != 0,  "cannot use register 0 in memory access");  return ra(x); }
1025 
1026   // register r is target
1027   static int rt(       Register    r)  { return rs(r); }
1028   static int rt(       int         x)  { return rs(x); }
1029   static int rta(      Register    r)  { return ra(r); }
1030   static int rta0mem(  Register    r)  { rta(r); return ra0mem(r); }
1031 
1032   static int sh1620(   int         x)  { return  opp_u_field(x,             20, 16); }
1033   static int sh30(     int         x)  { return  opp_u_field(x,             30, 30); }
1034   static int sh162030( int         x)  { return  sh1620(x & 0x1f) | sh30((x & 0x20) >> 5); }
1035   static int si(       int         x)  { return  opp_s_field(x,             31, 16); }
1036   static int spr(      int         x)  { return  opp_u_field(x,             20, 11); }
1037   static int sr(       int         x)  { return  opp_u_field(x,             15, 12); }
1038   static int tbr(      int         x)  { return  opp_u_field(x,             20, 11); }
1039   static int th(       int         x)  { return  opp_u_field(x,             10,  7); }
1040   static int thct(     int         x)  { assert((x&8) == 0, "must be valid cache specification");  return th(x); }
1041   static int thds(     int         x)  { assert((x&8) == 8, "must be valid stream specification"); return th(x); }
1042   static int to(       int         x)  { return  opp_u_field(x,             10,  6); }
1043   static int u(        int         x)  { return  opp_u_field(x,             19, 16); }
1044   static int ui(       int         x)  { return  opp_u_field(x,             31, 16); }
1045 
1046   // Support vector instructions for >= Power6.
1047   static int vra(      int         x)  { return  opp_u_field(x,             15, 11); }
1048   static int vrb(      int         x)  { return  opp_u_field(x,             20, 16); }
1049   static int vrc(      int         x)  { return  opp_u_field(x,             25, 21); }
1050   static int vrs(      int         x)  { return  opp_u_field(x,             10,  6); }
1051   static int vrt(      int         x)  { return  opp_u_field(x,             10,  6); }
1052 
1053   static int vra(   VectorRegister r)  { return  vra(r->encoding());}
1054   static int vrb(   VectorRegister r)  { return  vrb(r->encoding());}
1055   static int vrc(   VectorRegister r)  { return  vrc(r->encoding());}
1056   static int vrs(   VectorRegister r)  { return  vrs(r->encoding());}
1057   static int vrt(   VectorRegister r)  { return  vrt(r->encoding());}
1058 
1059   // Support Vector-Scalar (VSX) instructions.
1060   static int vsra(      int         x)  { return  opp_u_field(x,            15, 11); }
1061   static int vsrb(      int         x)  { return  opp_u_field(x,            20, 16); }
1062   static int vsrc(      int         x)  { return  opp_u_field(x,            25, 21); }
1063   static int vsrs(      int         x)  { return  opp_u_field(x,            10,  6); }
1064   static int vsrt(      int         x)  { return  opp_u_field(x,            10,  6); }
1065 
1066   static int vsra(   VectorSRegister r)  { return  vsra(r->encoding());}
1067   static int vsrb(   VectorSRegister r)  { return  vsrb(r->encoding());}
1068   static int vsrc(   VectorSRegister r)  { return  vsrc(r->encoding());}
1069   static int vsrs(   VectorSRegister r)  { return  vsrs(r->encoding());}
1070   static int vsrt(   VectorSRegister r)  { return  vsrt(r->encoding());}
1071 
1072   static int vsplt_uim( int        x)  { return  opp_u_field(x,             15, 12); } // for vsplt* instructions
1073   static int vsplti_sim(int        x)  { return  opp_u_field(x,             15, 11); } // for vsplti* instructions
1074   static int vsldoi_shb(int        x)  { return  opp_u_field(x,             25, 22); } // for vsldoi instruction
1075   static int vcmp_rc(   int        x)  { return  opp_u_field(x,             21, 21); } // for vcmp* instructions
1076 
1077   //static int xo1(     int        x)  { return  opp_u_field(x,             29, 21); }// is contained in our opcodes
1078   //static int xo2(     int        x)  { return  opp_u_field(x,             30, 21); }// is contained in our opcodes
1079   //static int xo3(     int        x)  { return  opp_u_field(x,             30, 22); }// is contained in our opcodes
1080   //static int xo4(     int        x)  { return  opp_u_field(x,             30, 26); }// is contained in our opcodes
1081   //static int xo5(     int        x)  { return  opp_u_field(x,             29, 27); }// is contained in our opcodes
1082   //static int xo6(     int        x)  { return  opp_u_field(x,             30, 27); }// is contained in our opcodes
1083   //static int xo7(     int        x)  { return  opp_u_field(x,             31, 30); }// is contained in our opcodes
1084 
1085  protected:
1086   // Compute relative address for branch.
1087   static intptr_t disp(intptr_t x, intptr_t off) {
1088     int xx = x - off;
1089     xx = xx >> 2;
1090     return xx;
1091   }
1092 
1093  public:
1094   // signed immediate, in low bits, nbits long
1095   static int simm(int x, int nbits) {
1096     assert_signed_range(x, nbits);
1097     return x & ((1 << nbits) - 1);
1098   }
1099 
1100   // unsigned immediate, in low bits, nbits long
1101   static int uimm(int x, int nbits) {
1102     assert_unsigned_const(x, nbits);
1103     return x & ((1 << nbits) - 1);
1104   }
1105 
1106   static void set_imm(int* instr, short s) {
1107     // imm is always in the lower 16 bits of the instruction,
1108     // so this is endian-neutral. Same for the get_imm below.
1109     uint32_t w = *(uint32_t *)instr;
1110     *instr = (int)((w & ~0x0000FFFF) | (s & 0x0000FFFF));
1111   }
1112 
1113   static int get_imm(address a, int instruction_number) {
1114     return (short)((int *)a)[instruction_number];
1115   }
1116 
1117   static inline int hi16_signed(  int x) { return (int)(int16_t)(x >> 16); }
1118   static inline int lo16_unsigned(int x) { return x & 0xffff; }
1119 
1120  protected:
1121 
1122   // Extract the top 32 bits in a 64 bit word.
1123   static int32_t hi32(int64_t x) {
1124     int32_t r = int32_t((uint64_t)x >> 32);
1125     return r;
1126   }
1127 
1128  public:
1129 
1130   static inline unsigned int align_addr(unsigned int addr, unsigned int a) {
1131     return ((addr + (a - 1)) & ~(a - 1));
1132   }
1133 
1134   static inline bool is_aligned(unsigned int addr, unsigned int a) {
1135     return (0 == addr % a);
1136   }
1137 
1138   void flush() {
1139     AbstractAssembler::flush();
1140   }
1141 
1142   inline void emit_int32(int);  // shadows AbstractAssembler::emit_int32
1143   inline void emit_data(int);
1144   inline void emit_data(int, RelocationHolder const&);
1145   inline void emit_data(int, relocInfo::relocType rtype);
1146 
1147   // Emit an address.
1148   inline address emit_addr(const address addr = NULL);
1149 
1150 #if !defined(ABI_ELFv2)
1151   // Emit a function descriptor with the specified entry point, TOC,
1152   // and ENV. If the entry point is NULL, the descriptor will point
1153   // just past the descriptor.
1154   // Use values from friend functions as defaults.
1155   inline address emit_fd(address entry = NULL,
1156                          address toc = (address) FunctionDescriptor::friend_toc,
1157                          address env = (address) FunctionDescriptor::friend_env);
1158 #endif
1159 
1160   /////////////////////////////////////////////////////////////////////////////////////
1161   // PPC instructions
1162   /////////////////////////////////////////////////////////////////////////////////////
1163 
1164   // Memory instructions use r0 as hard coded 0, e.g. to simulate loading
1165   // immediates. The normal instruction encoders enforce that r0 is not
1166   // passed to them. Use either extended mnemonics encoders or the special ra0
1167   // versions.
1168 
1169   // Issue an illegal instruction.
1170   inline void illtrap();
1171   static inline bool is_illtrap(int x);
1172 
1173   // PPC 1, section 3.3.8, Fixed-Point Arithmetic Instructions
1174   inline void addi( Register d, Register a, int si16);
1175   inline void addis(Register d, Register a, int si16);
1176  private:
1177   inline void addi_r0ok( Register d, Register a, int si16);
1178   inline void addis_r0ok(Register d, Register a, int si16);
1179  public:
1180   inline void addic_( Register d, Register a, int si16);
1181   inline void subfic( Register d, Register a, int si16);
1182   inline void add(    Register d, Register a, Register b);
1183   inline void add_(   Register d, Register a, Register b);
1184   inline void subf(   Register d, Register a, Register b);  // d = b - a    "Sub_from", as in ppc spec.
1185   inline void sub(    Register d, Register a, Register b);  // d = a - b    Swap operands of subf for readability.
1186   inline void subf_(  Register d, Register a, Register b);
1187   inline void addc(   Register d, Register a, Register b);
1188   inline void addc_(  Register d, Register a, Register b);
1189   inline void subfc(  Register d, Register a, Register b);
1190   inline void subfc_( Register d, Register a, Register b);
1191   inline void adde(   Register d, Register a, Register b);
1192   inline void adde_(  Register d, Register a, Register b);
1193   inline void subfe(  Register d, Register a, Register b);
1194   inline void subfe_( Register d, Register a, Register b);
1195   inline void neg(    Register d, Register a);
1196   inline void neg_(   Register d, Register a);
1197   inline void mulli(  Register d, Register a, int si16);
1198   inline void mulld(  Register d, Register a, Register b);
1199   inline void mulld_( Register d, Register a, Register b);
1200   inline void mullw(  Register d, Register a, Register b);
1201   inline void mullw_( Register d, Register a, Register b);
1202   inline void mulhw(  Register d, Register a, Register b);
1203   inline void mulhw_( Register d, Register a, Register b);
1204   inline void mulhwu( Register d, Register a, Register b);
1205   inline void mulhwu_(Register d, Register a, Register b);
1206   inline void mulhd(  Register d, Register a, Register b);
1207   inline void mulhd_( Register d, Register a, Register b);
1208   inline void mulhdu( Register d, Register a, Register b);
1209   inline void mulhdu_(Register d, Register a, Register b);
1210   inline void divd(   Register d, Register a, Register b);
1211   inline void divd_(  Register d, Register a, Register b);
1212   inline void divw(   Register d, Register a, Register b);
1213   inline void divw_(  Register d, Register a, Register b);
1214 
1215   // extended mnemonics
1216   inline void li(   Register d, int si16);
1217   inline void lis(  Register d, int si16);
1218   inline void addir(Register d, int si16, Register a);
1219 
1220   static bool is_addi(int x) {
1221      return ADDI_OPCODE == (x & ADDI_OPCODE_MASK);
1222   }
1223   static bool is_addis(int x) {
1224      return ADDIS_OPCODE == (x & ADDIS_OPCODE_MASK);
1225   }
1226   static bool is_bxx(int x) {
1227      return BXX_OPCODE == (x & BXX_OPCODE_MASK);
1228   }
1229   static bool is_b(int x) {
1230      return BXX_OPCODE == (x & BXX_OPCODE_MASK) && inv_lk_field(x) == 0;
1231   }
1232   static bool is_bl(int x) {
1233      return BXX_OPCODE == (x & BXX_OPCODE_MASK) && inv_lk_field(x) == 1;
1234   }
1235   static bool is_bcxx(int x) {
1236      return BCXX_OPCODE == (x & BCXX_OPCODE_MASK);
1237   }
1238   static bool is_bxx_or_bcxx(int x) {
1239      return is_bxx(x) || is_bcxx(x);
1240   }
1241   static bool is_bctrl(int x) {
1242      return x == 0x4e800421;
1243   }
1244   static bool is_bctr(int x) {
1245      return x == 0x4e800420;
1246   }
1247   static bool is_bclr(int x) {
1248      return BCLR_OPCODE == (x & XL_FORM_OPCODE_MASK);
1249   }
1250   static bool is_li(int x) {
1251      return is_addi(x) && inv_ra_field(x)==0;
1252   }
1253   static bool is_lis(int x) {
1254      return is_addis(x) && inv_ra_field(x)==0;
1255   }
1256   static bool is_mtctr(int x) {
1257      return MTCTR_OPCODE == (x & MTCTR_OPCODE_MASK);
1258   }
1259   static bool is_ld(int x) {
1260      return LD_OPCODE == (x & LD_OPCODE_MASK);
1261   }
1262   static bool is_std(int x) {
1263      return STD_OPCODE == (x & STD_OPCODE_MASK);
1264   }
1265   static bool is_stdu(int x) {
1266      return STDU_OPCODE == (x & STDU_OPCODE_MASK);
1267   }
1268   static bool is_stdx(int x) {
1269      return STDX_OPCODE == (x & STDX_OPCODE_MASK);
1270   }
1271   static bool is_stdux(int x) {
1272      return STDUX_OPCODE == (x & STDUX_OPCODE_MASK);
1273   }
1274   static bool is_stwx(int x) {
1275      return STWX_OPCODE == (x & STWX_OPCODE_MASK);
1276   }
1277   static bool is_stwux(int x) {
1278      return STWUX_OPCODE == (x & STWUX_OPCODE_MASK);
1279   }
1280   static bool is_stw(int x) {
1281      return STW_OPCODE == (x & STW_OPCODE_MASK);
1282   }
1283   static bool is_stwu(int x) {
1284      return STWU_OPCODE == (x & STWU_OPCODE_MASK);
1285   }
1286   static bool is_ori(int x) {
1287      return ORI_OPCODE == (x & ORI_OPCODE_MASK);
1288   };
1289   static bool is_oris(int x) {
1290      return ORIS_OPCODE == (x & ORIS_OPCODE_MASK);
1291   };
1292   static bool is_rldicr(int x) {
1293      return (RLDICR_OPCODE == (x & RLDICR_OPCODE_MASK));
1294   };
1295   static bool is_nop(int x) {
1296     return x == 0x60000000;
1297   }
1298   // endgroup opcode for Power6
1299   static bool is_endgroup(int x) {
1300     return is_ori(x) && inv_ra_field(x) == 1 && inv_rs_field(x) == 1 && inv_d1_field(x) == 0;
1301   }
1302 
1303 
1304  private:
1305   // PPC 1, section 3.3.9, Fixed-Point Compare Instructions
1306   inline void cmpi( ConditionRegister bf, int l, Register a, int si16);
1307   inline void cmp(  ConditionRegister bf, int l, Register a, Register b);
1308   inline void cmpli(ConditionRegister bf, int l, Register a, int ui16);
1309   inline void cmpl( ConditionRegister bf, int l, Register a, Register b);
1310 
1311  public:
1312   // extended mnemonics of Compare Instructions
1313   inline void cmpwi( ConditionRegister crx, Register a, int si16);
1314   inline void cmpdi( ConditionRegister crx, Register a, int si16);
1315   inline void cmpw(  ConditionRegister crx, Register a, Register b);
1316   inline void cmpd(  ConditionRegister crx, Register a, Register b);
1317   inline void cmplwi(ConditionRegister crx, Register a, int ui16);
1318   inline void cmpldi(ConditionRegister crx, Register a, int ui16);
1319   inline void cmplw( ConditionRegister crx, Register a, Register b);
1320   inline void cmpld( ConditionRegister crx, Register a, Register b);
1321 
1322   inline void isel(   Register d, Register a, Register b, int bc);
1323   // Convenient version which takes: Condition register, Condition code and invert flag. Omit b to keep old value.
1324   inline void isel(   Register d, ConditionRegister cr, Condition cc, bool inv, Register a, Register b = noreg);
1325   // Set d = 0 if (cr.cc) equals 1, otherwise b.
1326   inline void isel_0( Register d, ConditionRegister cr, Condition cc, Register b = noreg);
1327 
1328   // PPC 1, section 3.3.11, Fixed-Point Logical Instructions
1329          void andi(   Register a, Register s, int ui16);   // optimized version
1330   inline void andi_(  Register a, Register s, int ui16);
1331   inline void andis_( Register a, Register s, int ui16);
1332   inline void ori(    Register a, Register s, int ui16);
1333   inline void oris(   Register a, Register s, int ui16);
1334   inline void xori(   Register a, Register s, int ui16);
1335   inline void xoris(  Register a, Register s, int ui16);
1336   inline void andr(   Register a, Register s, Register b);  // suffixed by 'r' as 'and' is C++ keyword
1337   inline void and_(   Register a, Register s, Register b);
1338   // Turn or0(rx,rx,rx) into a nop and avoid that we accidently emit a
1339   // SMT-priority change instruction (see SMT instructions below).
1340   inline void or_unchecked(Register a, Register s, Register b);
1341   inline void orr(    Register a, Register s, Register b);  // suffixed by 'r' as 'or' is C++ keyword
1342   inline void or_(    Register a, Register s, Register b);
1343   inline void xorr(   Register a, Register s, Register b);  // suffixed by 'r' as 'xor' is C++ keyword
1344   inline void xor_(   Register a, Register s, Register b);
1345   inline void nand(   Register a, Register s, Register b);
1346   inline void nand_(  Register a, Register s, Register b);
1347   inline void nor(    Register a, Register s, Register b);
1348   inline void nor_(   Register a, Register s, Register b);
1349   inline void andc(   Register a, Register s, Register b);
1350   inline void andc_(  Register a, Register s, Register b);
1351   inline void orc(    Register a, Register s, Register b);
1352   inline void orc_(   Register a, Register s, Register b);
1353   inline void extsb(  Register a, Register s);
1354   inline void extsh(  Register a, Register s);
1355   inline void extsw(  Register a, Register s);
1356 
1357   // extended mnemonics
1358   inline void nop();
1359   // NOP for FP and BR units (different versions to allow them to be in one group)
1360   inline void fpnop0();
1361   inline void fpnop1();
1362   inline void brnop0();
1363   inline void brnop1();
1364   inline void brnop2();
1365 
1366   inline void mr(      Register d, Register s);
1367   inline void ori_opt( Register d, int ui16);
1368   inline void oris_opt(Register d, int ui16);
1369 
1370   // endgroup opcode for Power6
1371   inline void endgroup();
1372 
1373   // count instructions
1374   inline void cntlzw(  Register a, Register s);
1375   inline void cntlzw_( Register a, Register s);
1376   inline void cntlzd(  Register a, Register s);
1377   inline void cntlzd_( Register a, Register s);
1378 
1379   // PPC 1, section 3.3.12, Fixed-Point Rotate and Shift Instructions
1380   inline void sld(     Register a, Register s, Register b);
1381   inline void sld_(    Register a, Register s, Register b);
1382   inline void slw(     Register a, Register s, Register b);
1383   inline void slw_(    Register a, Register s, Register b);
1384   inline void srd(     Register a, Register s, Register b);
1385   inline void srd_(    Register a, Register s, Register b);
1386   inline void srw(     Register a, Register s, Register b);
1387   inline void srw_(    Register a, Register s, Register b);
1388   inline void srad(    Register a, Register s, Register b);
1389   inline void srad_(   Register a, Register s, Register b);
1390   inline void sraw(    Register a, Register s, Register b);
1391   inline void sraw_(   Register a, Register s, Register b);
1392   inline void sradi(   Register a, Register s, int sh6);
1393   inline void sradi_(  Register a, Register s, int sh6);
1394   inline void srawi(   Register a, Register s, int sh5);
1395   inline void srawi_(  Register a, Register s, int sh5);
1396 
1397   // extended mnemonics for Shift Instructions
1398   inline void sldi(    Register a, Register s, int sh6);
1399   inline void sldi_(   Register a, Register s, int sh6);
1400   inline void slwi(    Register a, Register s, int sh5);
1401   inline void slwi_(   Register a, Register s, int sh5);
1402   inline void srdi(    Register a, Register s, int sh6);
1403   inline void srdi_(   Register a, Register s, int sh6);
1404   inline void srwi(    Register a, Register s, int sh5);
1405   inline void srwi_(   Register a, Register s, int sh5);
1406 
1407   inline void clrrdi(  Register a, Register s, int ui6);
1408   inline void clrrdi_( Register a, Register s, int ui6);
1409   inline void clrldi(  Register a, Register s, int ui6);
1410   inline void clrldi_( Register a, Register s, int ui6);
1411   inline void clrlsldi(Register a, Register s, int clrl6, int shl6);
1412   inline void clrlsldi_(Register a, Register s, int clrl6, int shl6);
1413   inline void extrdi(  Register a, Register s, int n, int b);
1414   // testbit with condition register
1415   inline void testbitdi(ConditionRegister cr, Register a, Register s, int ui6);
1416 
1417   // rotate instructions
1418   inline void rotldi(  Register a, Register s, int n);
1419   inline void rotrdi(  Register a, Register s, int n);
1420   inline void rotlwi(  Register a, Register s, int n);
1421   inline void rotrwi(  Register a, Register s, int n);
1422 
1423   // Rotate Instructions
1424   inline void rldic(   Register a, Register s, int sh6, int mb6);
1425   inline void rldic_(  Register a, Register s, int sh6, int mb6);
1426   inline void rldicr(  Register a, Register s, int sh6, int mb6);
1427   inline void rldicr_( Register a, Register s, int sh6, int mb6);
1428   inline void rldicl(  Register a, Register s, int sh6, int mb6);
1429   inline void rldicl_( Register a, Register s, int sh6, int mb6);
1430   inline void rlwinm(  Register a, Register s, int sh5, int mb5, int me5);
1431   inline void rlwinm_( Register a, Register s, int sh5, int mb5, int me5);
1432   inline void rldimi(  Register a, Register s, int sh6, int mb6);
1433   inline void rldimi_( Register a, Register s, int sh6, int mb6);
1434   inline void rlwimi(  Register a, Register s, int sh5, int mb5, int me5);
1435   inline void insrdi(  Register a, Register s, int n,   int b);
1436   inline void insrwi(  Register a, Register s, int n,   int b);
1437 
1438   // PPC 1, section 3.3.2 Fixed-Point Load Instructions
1439   // 4 bytes
1440   inline void lwzx( Register d, Register s1, Register s2);
1441   inline void lwz(  Register d, int si16,    Register s1);
1442   inline void lwzu( Register d, int si16,    Register s1);
1443 
1444   // 4 bytes
1445   inline void lwax( Register d, Register s1, Register s2);
1446   inline void lwa(  Register d, int si16,    Register s1);
1447 
1448   // 4 bytes reversed
1449   inline void lwbrx( Register d, Register s1, Register s2);
1450 
1451   // 2 bytes
1452   inline void lhzx( Register d, Register s1, Register s2);
1453   inline void lhz(  Register d, int si16,    Register s1);
1454   inline void lhzu( Register d, int si16,    Register s1);
1455 
1456   // 2 bytes reversed
1457   inline void lhbrx( Register d, Register s1, Register s2);
1458 
1459   // 2 bytes
1460   inline void lhax( Register d, Register s1, Register s2);
1461   inline void lha(  Register d, int si16,    Register s1);
1462   inline void lhau( Register d, int si16,    Register s1);
1463 
1464   // 1 byte
1465   inline void lbzx( Register d, Register s1, Register s2);
1466   inline void lbz(  Register d, int si16,    Register s1);
1467   inline void lbzu( Register d, int si16,    Register s1);
1468 
1469   // 8 bytes
1470   inline void ldx(  Register d, Register s1, Register s2);
1471   inline void ld(   Register d, int si16,    Register s1);
1472   inline void ldu(  Register d, int si16,    Register s1);
1473 
1474   //  PPC 1, section 3.3.3 Fixed-Point Store Instructions
1475   inline void stwx( Register d, Register s1, Register s2);
1476   inline void stw(  Register d, int si16,    Register s1);
1477   inline void stwu( Register d, int si16,    Register s1);
1478 
1479   inline void sthx( Register d, Register s1, Register s2);
1480   inline void sth(  Register d, int si16,    Register s1);
1481   inline void sthu( Register d, int si16,    Register s1);
1482 
1483   inline void stbx( Register d, Register s1, Register s2);
1484   inline void stb(  Register d, int si16,    Register s1);
1485   inline void stbu( Register d, int si16,    Register s1);
1486 
1487   inline void stdx( Register d, Register s1, Register s2);
1488   inline void std(  Register d, int si16,    Register s1);
1489   inline void stdu( Register d, int si16,    Register s1);
1490   inline void stdux(Register s, Register a,  Register b);
1491 
1492   // PPC 1, section 3.3.13 Move To/From System Register Instructions
1493   inline void mtlr( Register s1);
1494   inline void mflr( Register d);
1495   inline void mtctr(Register s1);
1496   inline void mfctr(Register d);
1497   inline void mtcrf(int fxm, Register s);
1498   inline void mfcr( Register d);
1499   inline void mcrf( ConditionRegister crd, ConditionRegister cra);
1500   inline void mtcr( Register s);
1501 
1502   // Special purpose registers
1503   // Exception Register
1504   inline void mtxer(Register s1);
1505   inline void mfxer(Register d);
1506   // Vector Register Save Register
1507   inline void mtvrsave(Register s1);
1508   inline void mfvrsave(Register d);
1509   // Timebase
1510   inline void mftb(Register d);
1511   // Introduced with Power 8:
1512   // Data Stream Control Register
1513   inline void mtdscr(Register s1);
1514   inline void mfdscr(Register d );
1515   // Transactional Memory Registers
1516   inline void mftfhar(Register d);
1517   inline void mftfiar(Register d);
1518   inline void mftexasr(Register d);
1519   inline void mftexasru(Register d);
1520 
1521   // PPC 1, section 2.4.1 Branch Instructions
1522   inline void b(  address a, relocInfo::relocType rt = relocInfo::none);
1523   inline void b(  Label& L);
1524   inline void bl( address a, relocInfo::relocType rt = relocInfo::none);
1525   inline void bl( Label& L);
1526   inline void bc( int boint, int biint, address a, relocInfo::relocType rt = relocInfo::none);
1527   inline void bc( int boint, int biint, Label& L);
1528   inline void bcl(int boint, int biint, address a, relocInfo::relocType rt = relocInfo::none);
1529   inline void bcl(int boint, int biint, Label& L);
1530 
1531   inline void bclr(  int boint, int biint, int bhint, relocInfo::relocType rt = relocInfo::none);
1532   inline void bclrl( int boint, int biint, int bhint, relocInfo::relocType rt = relocInfo::none);
1533   inline void bcctr( int boint, int biint, int bhint = bhintbhBCCTRisNotReturnButSame,
1534                          relocInfo::relocType rt = relocInfo::none);
1535   inline void bcctrl(int boint, int biint, int bhint = bhintbhBCLRisReturn,
1536                          relocInfo::relocType rt = relocInfo::none);
1537 
1538   // helper function for b, bcxx
1539   inline bool is_within_range_of_b(address a, address pc);
1540   inline bool is_within_range_of_bcxx(address a, address pc);
1541 
1542   // get the destination of a bxx branch (b, bl, ba, bla)
1543   static inline address  bxx_destination(address baddr);
1544   static inline address  bxx_destination(int instr, address pc);
1545   static inline intptr_t bxx_destination_offset(int instr, intptr_t bxx_pos);
1546 
1547   // extended mnemonics for branch instructions
1548   inline void blt(ConditionRegister crx, Label& L);
1549   inline void bgt(ConditionRegister crx, Label& L);
1550   inline void beq(ConditionRegister crx, Label& L);
1551   inline void bso(ConditionRegister crx, Label& L);
1552   inline void bge(ConditionRegister crx, Label& L);
1553   inline void ble(ConditionRegister crx, Label& L);
1554   inline void bne(ConditionRegister crx, Label& L);
1555   inline void bns(ConditionRegister crx, Label& L);
1556 
1557   // Branch instructions with static prediction hints.
1558   inline void blt_predict_taken(    ConditionRegister crx, Label& L);
1559   inline void bgt_predict_taken(    ConditionRegister crx, Label& L);
1560   inline void beq_predict_taken(    ConditionRegister crx, Label& L);
1561   inline void bso_predict_taken(    ConditionRegister crx, Label& L);
1562   inline void bge_predict_taken(    ConditionRegister crx, Label& L);
1563   inline void ble_predict_taken(    ConditionRegister crx, Label& L);
1564   inline void bne_predict_taken(    ConditionRegister crx, Label& L);
1565   inline void bns_predict_taken(    ConditionRegister crx, Label& L);
1566   inline void blt_predict_not_taken(ConditionRegister crx, Label& L);
1567   inline void bgt_predict_not_taken(ConditionRegister crx, Label& L);
1568   inline void beq_predict_not_taken(ConditionRegister crx, Label& L);
1569   inline void bso_predict_not_taken(ConditionRegister crx, Label& L);
1570   inline void bge_predict_not_taken(ConditionRegister crx, Label& L);
1571   inline void ble_predict_not_taken(ConditionRegister crx, Label& L);
1572   inline void bne_predict_not_taken(ConditionRegister crx, Label& L);
1573   inline void bns_predict_not_taken(ConditionRegister crx, Label& L);
1574 
1575   // for use in conjunction with testbitdi:
1576   inline void btrue( ConditionRegister crx, Label& L);
1577   inline void bfalse(ConditionRegister crx, Label& L);
1578 
1579   inline void bltl(ConditionRegister crx, Label& L);
1580   inline void bgtl(ConditionRegister crx, Label& L);
1581   inline void beql(ConditionRegister crx, Label& L);
1582   inline void bsol(ConditionRegister crx, Label& L);
1583   inline void bgel(ConditionRegister crx, Label& L);
1584   inline void blel(ConditionRegister crx, Label& L);
1585   inline void bnel(ConditionRegister crx, Label& L);
1586   inline void bnsl(ConditionRegister crx, Label& L);
1587 
1588   // extended mnemonics for Branch Instructions via LR
1589   // We use `blr' for returns.
1590   inline void blr(relocInfo::relocType rt = relocInfo::none);
1591 
1592   // extended mnemonics for Branch Instructions with CTR
1593   // bdnz means `decrement CTR and jump to L if CTR is not zero'
1594   inline void bdnz(Label& L);
1595   // Decrement and branch if result is zero.
1596   inline void bdz(Label& L);
1597   // we use `bctr[l]' for jumps/calls in function descriptor glue
1598   // code, e.g. calls to runtime functions
1599   inline void bctr( relocInfo::relocType rt = relocInfo::none);
1600   inline void bctrl(relocInfo::relocType rt = relocInfo::none);
1601   // conditional jumps/branches via CTR
1602   inline void beqctr( ConditionRegister crx, relocInfo::relocType rt = relocInfo::none);
1603   inline void beqctrl(ConditionRegister crx, relocInfo::relocType rt = relocInfo::none);
1604   inline void bnectr( ConditionRegister crx, relocInfo::relocType rt = relocInfo::none);
1605   inline void bnectrl(ConditionRegister crx, relocInfo::relocType rt = relocInfo::none);
1606 
1607   // condition register logic instructions
1608   inline void crand( int d, int s1, int s2);
1609   inline void crnand(int d, int s1, int s2);
1610   inline void cror(  int d, int s1, int s2);
1611   inline void crxor( int d, int s1, int s2);
1612   inline void crnor( int d, int s1, int s2);
1613   inline void creqv( int d, int s1, int s2);
1614   inline void crandc(int d, int s1, int s2);
1615   inline void crorc( int d, int s1, int s2);
1616 
1617   // icache and dcache related instructions
1618   inline void icbi(  Register s1, Register s2);
1619   //inline void dcba(Register s1, Register s2); // Instruction for embedded processor only.
1620   inline void dcbz(  Register s1, Register s2);
1621   inline void dcbst( Register s1, Register s2);
1622   inline void dcbf(  Register s1, Register s2);
1623 
1624   enum ct_cache_specification {
1625     ct_primary_cache   = 0,
1626     ct_secondary_cache = 2
1627   };
1628   // dcache read hint
1629   inline void dcbt(    Register s1, Register s2);
1630   inline void dcbtct(  Register s1, Register s2, int ct);
1631   inline void dcbtds(  Register s1, Register s2, int ds);
1632   // dcache write hint
1633   inline void dcbtst(  Register s1, Register s2);
1634   inline void dcbtstct(Register s1, Register s2, int ct);
1635 
1636   //  machine barrier instructions:
1637   //
1638   //  - sync    two-way memory barrier, aka fence
1639   //  - lwsync  orders  Store|Store,
1640   //                     Load|Store,
1641   //                     Load|Load,
1642   //            but not Store|Load
1643   //  - eieio   orders memory accesses for device memory (only)
1644   //  - isync   invalidates speculatively executed instructions
1645   //            From the Power ISA 2.06 documentation:
1646   //             "[...] an isync instruction prevents the execution of
1647   //            instructions following the isync until instructions
1648   //            preceding the isync have completed, [...]"
1649   //            From IBM's AIX assembler reference:
1650   //             "The isync [...] instructions causes the processor to
1651   //            refetch any instructions that might have been fetched
1652   //            prior to the isync instruction. The instruction isync
1653   //            causes the processor to wait for all previous instructions
1654   //            to complete. Then any instructions already fetched are
1655   //            discarded and instruction processing continues in the
1656   //            environment established by the previous instructions."
1657   //
1658   //  semantic barrier instructions:
1659   //  (as defined in orderAccess.hpp)
1660   //
1661   //  - release  orders Store|Store,       (maps to lwsync)
1662   //                     Load|Store
1663   //  - acquire  orders  Load|Store,       (maps to lwsync)
1664   //                     Load|Load
1665   //  - fence    orders Store|Store,       (maps to sync)
1666   //                     Load|Store,
1667   //                     Load|Load,
1668   //                    Store|Load
1669   //
1670  private:
1671   inline void sync(int l);
1672  public:
1673   inline void sync();
1674   inline void lwsync();
1675   inline void ptesync();
1676   inline void eieio();
1677   inline void isync();
1678   inline void elemental_membar(int e); // Elemental Memory Barriers (>=Power 8)
1679 
1680   // atomics
1681   inline void lwarx_unchecked(Register d, Register a, Register b, int eh1 = 0);
1682   inline void ldarx_unchecked(Register d, Register a, Register b, int eh1 = 0);
1683   inline void lqarx_unchecked(Register d, Register a, Register b, int eh1 = 0);
1684   inline bool lxarx_hint_exclusive_access();
1685   inline void lwarx(  Register d, Register a, Register b, bool hint_exclusive_access = false);
1686   inline void ldarx(  Register d, Register a, Register b, bool hint_exclusive_access = false);
1687   inline void lqarx(  Register d, Register a, Register b, bool hint_exclusive_access = false);
1688   inline void stwcx_( Register s, Register a, Register b);
1689   inline void stdcx_( Register s, Register a, Register b);
1690   inline void stqcx_( Register s, Register a, Register b);
1691 
1692   // Instructions for adjusting thread priority for simultaneous
1693   // multithreading (SMT) on Power5.
1694  private:
1695   inline void smt_prio_very_low();
1696   inline void smt_prio_medium_high();
1697   inline void smt_prio_high();
1698 
1699  public:
1700   inline void smt_prio_low();
1701   inline void smt_prio_medium_low();
1702   inline void smt_prio_medium();
1703 
1704   // trap instructions
1705   inline void twi_0(Register a); // for load with acquire semantics use load+twi_0+isync (trap can't occur)
1706   // NOT FOR DIRECT USE!!
1707  protected:
1708   inline void tdi_unchecked(int tobits, Register a, int si16);
1709   inline void twi_unchecked(int tobits, Register a, int si16);
1710   inline void tdi(          int tobits, Register a, int si16);   // asserts UseSIGTRAP
1711   inline void twi(          int tobits, Register a, int si16);   // asserts UseSIGTRAP
1712   inline void td(           int tobits, Register a, Register b); // asserts UseSIGTRAP
1713   inline void tw(           int tobits, Register a, Register b); // asserts UseSIGTRAP
1714 
1715   static bool is_tdi(int x, int tobits, int ra, int si16) {
1716      return (TDI_OPCODE == (x & TDI_OPCODE_MASK))
1717          && (tobits == inv_to_field(x))
1718          && (ra == -1/*any reg*/ || ra == inv_ra_field(x))
1719          && (si16 == inv_si_field(x));
1720   }
1721 
1722   static bool is_twi(int x, int tobits, int ra, int si16) {
1723      return (TWI_OPCODE == (x & TWI_OPCODE_MASK))
1724          && (tobits == inv_to_field(x))
1725          && (ra == -1/*any reg*/ || ra == inv_ra_field(x))
1726          && (si16 == inv_si_field(x));
1727   }
1728 
1729   static bool is_twi(int x, int tobits, int ra) {
1730      return (TWI_OPCODE == (x & TWI_OPCODE_MASK))
1731          && (tobits == inv_to_field(x))
1732          && (ra == -1/*any reg*/ || ra == inv_ra_field(x));
1733   }
1734 
1735   static bool is_td(int x, int tobits, int ra, int rb) {
1736      return (TD_OPCODE == (x & TD_OPCODE_MASK))
1737          && (tobits == inv_to_field(x))
1738          && (ra == -1/*any reg*/ || ra == inv_ra_field(x))
1739          && (rb == -1/*any reg*/ || rb == inv_rb_field(x));
1740   }
1741 
1742   static bool is_tw(int x, int tobits, int ra, int rb) {
1743      return (TW_OPCODE == (x & TW_OPCODE_MASK))
1744          && (tobits == inv_to_field(x))
1745          && (ra == -1/*any reg*/ || ra == inv_ra_field(x))
1746          && (rb == -1/*any reg*/ || rb == inv_rb_field(x));
1747   }
1748 
1749  public:
1750   // PPC floating point instructions
1751   // PPC 1, section 4.6.2 Floating-Point Load Instructions
1752   inline void lfs(  FloatRegister d, int si16,   Register a);
1753   inline void lfsu( FloatRegister d, int si16,   Register a);
1754   inline void lfsx( FloatRegister d, Register a, Register b);
1755   inline void lfd(  FloatRegister d, int si16,   Register a);
1756   inline void lfdu( FloatRegister d, int si16,   Register a);
1757   inline void lfdx( FloatRegister d, Register a, Register b);
1758 
1759   // PPC 1, section 4.6.3 Floating-Point Store Instructions
1760   inline void stfs(  FloatRegister s, int si16,   Register a);
1761   inline void stfsu( FloatRegister s, int si16,   Register a);
1762   inline void stfsx( FloatRegister s, Register a, Register b);
1763   inline void stfd(  FloatRegister s, int si16,   Register a);
1764   inline void stfdu( FloatRegister s, int si16,   Register a);
1765   inline void stfdx( FloatRegister s, Register a, Register b);
1766 
1767   // PPC 1, section 4.6.4 Floating-Point Move Instructions
1768   inline void fmr(  FloatRegister d, FloatRegister b);
1769   inline void fmr_( FloatRegister d, FloatRegister b);
1770 
1771   //  inline void mffgpr( FloatRegister d, Register b);
1772   //  inline void mftgpr( Register d, FloatRegister b);
1773   inline void cmpb(   Register a, Register s, Register b);
1774   inline void popcntb(Register a, Register s);
1775   inline void popcntw(Register a, Register s);
1776   inline void popcntd(Register a, Register s);
1777 
1778   inline void fneg(  FloatRegister d, FloatRegister b);
1779   inline void fneg_( FloatRegister d, FloatRegister b);
1780   inline void fabs(  FloatRegister d, FloatRegister b);
1781   inline void fabs_( FloatRegister d, FloatRegister b);
1782   inline void fnabs( FloatRegister d, FloatRegister b);
1783   inline void fnabs_(FloatRegister d, FloatRegister b);
1784 
1785   // PPC 1, section 4.6.5.1 Floating-Point Elementary Arithmetic Instructions
1786   inline void fadd(  FloatRegister d, FloatRegister a, FloatRegister b);
1787   inline void fadd_( FloatRegister d, FloatRegister a, FloatRegister b);
1788   inline void fadds( FloatRegister d, FloatRegister a, FloatRegister b);
1789   inline void fadds_(FloatRegister d, FloatRegister a, FloatRegister b);
1790   inline void fsub(  FloatRegister d, FloatRegister a, FloatRegister b);
1791   inline void fsub_( FloatRegister d, FloatRegister a, FloatRegister b);
1792   inline void fsubs( FloatRegister d, FloatRegister a, FloatRegister b);
1793   inline void fsubs_(FloatRegister d, FloatRegister a, FloatRegister b);
1794   inline void fmul(  FloatRegister d, FloatRegister a, FloatRegister c);
1795   inline void fmul_( FloatRegister d, FloatRegister a, FloatRegister c);
1796   inline void fmuls( FloatRegister d, FloatRegister a, FloatRegister c);
1797   inline void fmuls_(FloatRegister d, FloatRegister a, FloatRegister c);
1798   inline void fdiv(  FloatRegister d, FloatRegister a, FloatRegister b);
1799   inline void fdiv_( FloatRegister d, FloatRegister a, FloatRegister b);
1800   inline void fdivs( FloatRegister d, FloatRegister a, FloatRegister b);
1801   inline void fdivs_(FloatRegister d, FloatRegister a, FloatRegister b);
1802 
1803   // PPC 1, section 4.6.6 Floating-Point Rounding and Conversion Instructions
1804   inline void frsp(  FloatRegister d, FloatRegister b);
1805   inline void fctid( FloatRegister d, FloatRegister b);
1806   inline void fctidz(FloatRegister d, FloatRegister b);
1807   inline void fctiw( FloatRegister d, FloatRegister b);
1808   inline void fctiwz(FloatRegister d, FloatRegister b);
1809   inline void fcfid( FloatRegister d, FloatRegister b);
1810   inline void fcfids(FloatRegister d, FloatRegister b);
1811 
1812   // PPC 1, section 4.6.7 Floating-Point Compare Instructions
1813   inline void fcmpu( ConditionRegister crx, FloatRegister a, FloatRegister b);
1814 
1815   inline void fsqrt( FloatRegister d, FloatRegister b);
1816   inline void fsqrts(FloatRegister d, FloatRegister b);
1817 
1818   // Vector instructions for >= Power6.
1819   inline void lvebx(    VectorRegister d, Register s1, Register s2);
1820   inline void lvehx(    VectorRegister d, Register s1, Register s2);
1821   inline void lvewx(    VectorRegister d, Register s1, Register s2);
1822   inline void lvx(      VectorRegister d, Register s1, Register s2);
1823   inline void lvxl(     VectorRegister d, Register s1, Register s2);
1824   inline void stvebx(   VectorRegister d, Register s1, Register s2);
1825   inline void stvehx(   VectorRegister d, Register s1, Register s2);
1826   inline void stvewx(   VectorRegister d, Register s1, Register s2);
1827   inline void stvx(     VectorRegister d, Register s1, Register s2);
1828   inline void stvxl(    VectorRegister d, Register s1, Register s2);
1829   inline void lvsl(     VectorRegister d, Register s1, Register s2);
1830   inline void lvsr(     VectorRegister d, Register s1, Register s2);
1831   inline void vpkpx(    VectorRegister d, VectorRegister a, VectorRegister b);
1832   inline void vpkshss(  VectorRegister d, VectorRegister a, VectorRegister b);
1833   inline void vpkswss(  VectorRegister d, VectorRegister a, VectorRegister b);
1834   inline void vpkshus(  VectorRegister d, VectorRegister a, VectorRegister b);
1835   inline void vpkswus(  VectorRegister d, VectorRegister a, VectorRegister b);
1836   inline void vpkuhum(  VectorRegister d, VectorRegister a, VectorRegister b);
1837   inline void vpkuwum(  VectorRegister d, VectorRegister a, VectorRegister b);
1838   inline void vpkuhus(  VectorRegister d, VectorRegister a, VectorRegister b);
1839   inline void vpkuwus(  VectorRegister d, VectorRegister a, VectorRegister b);
1840   inline void vupkhpx(  VectorRegister d, VectorRegister b);
1841   inline void vupkhsb(  VectorRegister d, VectorRegister b);
1842   inline void vupkhsh(  VectorRegister d, VectorRegister b);
1843   inline void vupklpx(  VectorRegister d, VectorRegister b);
1844   inline void vupklsb(  VectorRegister d, VectorRegister b);
1845   inline void vupklsh(  VectorRegister d, VectorRegister b);
1846   inline void vmrghb(   VectorRegister d, VectorRegister a, VectorRegister b);
1847   inline void vmrghw(   VectorRegister d, VectorRegister a, VectorRegister b);
1848   inline void vmrghh(   VectorRegister d, VectorRegister a, VectorRegister b);
1849   inline void vmrglb(   VectorRegister d, VectorRegister a, VectorRegister b);
1850   inline void vmrglw(   VectorRegister d, VectorRegister a, VectorRegister b);
1851   inline void vmrglh(   VectorRegister d, VectorRegister a, VectorRegister b);
1852   inline void vsplt(    VectorRegister d, int ui4,          VectorRegister b);
1853   inline void vsplth(   VectorRegister d, int ui3,          VectorRegister b);
1854   inline void vspltw(   VectorRegister d, int ui2,          VectorRegister b);
1855   inline void vspltisb( VectorRegister d, int si5);
1856   inline void vspltish( VectorRegister d, int si5);
1857   inline void vspltisw( VectorRegister d, int si5);
1858   inline void vperm(    VectorRegister d, VectorRegister a, VectorRegister b, VectorRegister c);
1859   inline void vsel(     VectorRegister d, VectorRegister a, VectorRegister b, VectorRegister c);
1860   inline void vsl(      VectorRegister d, VectorRegister a, VectorRegister b);
1861   inline void vsldoi(   VectorRegister d, VectorRegister a, VectorRegister b, int si4);
1862   inline void vslo(     VectorRegister d, VectorRegister a, VectorRegister b);
1863   inline void vsr(      VectorRegister d, VectorRegister a, VectorRegister b);
1864   inline void vsro(     VectorRegister d, VectorRegister a, VectorRegister b);
1865   inline void vaddcuw(  VectorRegister d, VectorRegister a, VectorRegister b);
1866   inline void vaddshs(  VectorRegister d, VectorRegister a, VectorRegister b);
1867   inline void vaddsbs(  VectorRegister d, VectorRegister a, VectorRegister b);
1868   inline void vaddsws(  VectorRegister d, VectorRegister a, VectorRegister b);
1869   inline void vaddubm(  VectorRegister d, VectorRegister a, VectorRegister b);
1870   inline void vadduwm(  VectorRegister d, VectorRegister a, VectorRegister b);
1871   inline void vadduhm(  VectorRegister d, VectorRegister a, VectorRegister b);
1872   inline void vaddubs(  VectorRegister d, VectorRegister a, VectorRegister b);
1873   inline void vadduws(  VectorRegister d, VectorRegister a, VectorRegister b);
1874   inline void vadduhs(  VectorRegister d, VectorRegister a, VectorRegister b);
1875   inline void vsubcuw(  VectorRegister d, VectorRegister a, VectorRegister b);
1876   inline void vsubshs(  VectorRegister d, VectorRegister a, VectorRegister b);
1877   inline void vsubsbs(  VectorRegister d, VectorRegister a, VectorRegister b);
1878   inline void vsubsws(  VectorRegister d, VectorRegister a, VectorRegister b);
1879   inline void vsububm(  VectorRegister d, VectorRegister a, VectorRegister b);
1880   inline void vsubuwm(  VectorRegister d, VectorRegister a, VectorRegister b);
1881   inline void vsubuhm(  VectorRegister d, VectorRegister a, VectorRegister b);
1882   inline void vsububs(  VectorRegister d, VectorRegister a, VectorRegister b);
1883   inline void vsubuws(  VectorRegister d, VectorRegister a, VectorRegister b);
1884   inline void vsubuhs(  VectorRegister d, VectorRegister a, VectorRegister b);
1885   inline void vmulesb(  VectorRegister d, VectorRegister a, VectorRegister b);
1886   inline void vmuleub(  VectorRegister d, VectorRegister a, VectorRegister b);
1887   inline void vmulesh(  VectorRegister d, VectorRegister a, VectorRegister b);
1888   inline void vmuleuh(  VectorRegister d, VectorRegister a, VectorRegister b);
1889   inline void vmulosb(  VectorRegister d, VectorRegister a, VectorRegister b);
1890   inline void vmuloub(  VectorRegister d, VectorRegister a, VectorRegister b);
1891   inline void vmulosh(  VectorRegister d, VectorRegister a, VectorRegister b);
1892   inline void vmulouh(  VectorRegister d, VectorRegister a, VectorRegister b);
1893   inline void vmhaddshs(VectorRegister d, VectorRegister a, VectorRegister b, VectorRegister c);
1894   inline void vmhraddshs(VectorRegister d,VectorRegister a, VectorRegister b, VectorRegister c);
1895   inline void vmladduhm(VectorRegister d, VectorRegister a, VectorRegister b, VectorRegister c);
1896   inline void vmsubuhm( VectorRegister d, VectorRegister a, VectorRegister b, VectorRegister c);
1897   inline void vmsummbm( VectorRegister d, VectorRegister a, VectorRegister b, VectorRegister c);
1898   inline void vmsumshm( VectorRegister d, VectorRegister a, VectorRegister b, VectorRegister c);
1899   inline void vmsumshs( VectorRegister d, VectorRegister a, VectorRegister b, VectorRegister c);
1900   inline void vmsumuhm( VectorRegister d, VectorRegister a, VectorRegister b, VectorRegister c);
1901   inline void vmsumuhs( VectorRegister d, VectorRegister a, VectorRegister b, VectorRegister c);
1902   inline void vsumsws(  VectorRegister d, VectorRegister a, VectorRegister b);
1903   inline void vsum2sws( VectorRegister d, VectorRegister a, VectorRegister b);
1904   inline void vsum4sbs( VectorRegister d, VectorRegister a, VectorRegister b);
1905   inline void vsum4ubs( VectorRegister d, VectorRegister a, VectorRegister b);
1906   inline void vsum4shs( VectorRegister d, VectorRegister a, VectorRegister b);
1907   inline void vavgsb(   VectorRegister d, VectorRegister a, VectorRegister b);
1908   inline void vavgsw(   VectorRegister d, VectorRegister a, VectorRegister b);
1909   inline void vavgsh(   VectorRegister d, VectorRegister a, VectorRegister b);
1910   inline void vavgub(   VectorRegister d, VectorRegister a, VectorRegister b);
1911   inline void vavguw(   VectorRegister d, VectorRegister a, VectorRegister b);
1912   inline void vavguh(   VectorRegister d, VectorRegister a, VectorRegister b);
1913   inline void vmaxsb(   VectorRegister d, VectorRegister a, VectorRegister b);
1914   inline void vmaxsw(   VectorRegister d, VectorRegister a, VectorRegister b);
1915   inline void vmaxsh(   VectorRegister d, VectorRegister a, VectorRegister b);
1916   inline void vmaxub(   VectorRegister d, VectorRegister a, VectorRegister b);
1917   inline void vmaxuw(   VectorRegister d, VectorRegister a, VectorRegister b);
1918   inline void vmaxuh(   VectorRegister d, VectorRegister a, VectorRegister b);
1919   inline void vminsb(   VectorRegister d, VectorRegister a, VectorRegister b);
1920   inline void vminsw(   VectorRegister d, VectorRegister a, VectorRegister b);
1921   inline void vminsh(   VectorRegister d, VectorRegister a, VectorRegister b);
1922   inline void vminub(   VectorRegister d, VectorRegister a, VectorRegister b);
1923   inline void vminuw(   VectorRegister d, VectorRegister a, VectorRegister b);
1924   inline void vminuh(   VectorRegister d, VectorRegister a, VectorRegister b);
1925   inline void vcmpequb( VectorRegister d, VectorRegister a, VectorRegister b);
1926   inline void vcmpequh( VectorRegister d, VectorRegister a, VectorRegister b);
1927   inline void vcmpequw( VectorRegister d, VectorRegister a, VectorRegister b);
1928   inline void vcmpgtsh( VectorRegister d, VectorRegister a, VectorRegister b);
1929   inline void vcmpgtsb( VectorRegister d, VectorRegister a, VectorRegister b);
1930   inline void vcmpgtsw( VectorRegister d, VectorRegister a, VectorRegister b);
1931   inline void vcmpgtub( VectorRegister d, VectorRegister a, VectorRegister b);
1932   inline void vcmpgtuh( VectorRegister d, VectorRegister a, VectorRegister b);
1933   inline void vcmpgtuw( VectorRegister d, VectorRegister a, VectorRegister b);
1934   inline void vcmpequb_(VectorRegister d, VectorRegister a, VectorRegister b);
1935   inline void vcmpequh_(VectorRegister d, VectorRegister a, VectorRegister b);
1936   inline void vcmpequw_(VectorRegister d, VectorRegister a, VectorRegister b);
1937   inline void vcmpgtsh_(VectorRegister d, VectorRegister a, VectorRegister b);
1938   inline void vcmpgtsb_(VectorRegister d, VectorRegister a, VectorRegister b);
1939   inline void vcmpgtsw_(VectorRegister d, VectorRegister a, VectorRegister b);
1940   inline void vcmpgtub_(VectorRegister d, VectorRegister a, VectorRegister b);
1941   inline void vcmpgtuh_(VectorRegister d, VectorRegister a, VectorRegister b);
1942   inline void vcmpgtuw_(VectorRegister d, VectorRegister a, VectorRegister b);
1943   inline void vand(     VectorRegister d, VectorRegister a, VectorRegister b);
1944   inline void vandc(    VectorRegister d, VectorRegister a, VectorRegister b);
1945   inline void vnor(     VectorRegister d, VectorRegister a, VectorRegister b);
1946   inline void vor(      VectorRegister d, VectorRegister a, VectorRegister b);
1947   inline void vxor(     VectorRegister d, VectorRegister a, VectorRegister b);
1948   inline void vrld(     VectorRegister d, VectorRegister a, VectorRegister b);
1949   inline void vrlb(     VectorRegister d, VectorRegister a, VectorRegister b);
1950   inline void vrlw(     VectorRegister d, VectorRegister a, VectorRegister b);
1951   inline void vrlh(     VectorRegister d, VectorRegister a, VectorRegister b);
1952   inline void vslb(     VectorRegister d, VectorRegister a, VectorRegister b);
1953   inline void vskw(     VectorRegister d, VectorRegister a, VectorRegister b);
1954   inline void vslh(     VectorRegister d, VectorRegister a, VectorRegister b);
1955   inline void vsrb(     VectorRegister d, VectorRegister a, VectorRegister b);
1956   inline void vsrw(     VectorRegister d, VectorRegister a, VectorRegister b);
1957   inline void vsrh(     VectorRegister d, VectorRegister a, VectorRegister b);
1958   inline void vsrab(    VectorRegister d, VectorRegister a, VectorRegister b);
1959   inline void vsraw(    VectorRegister d, VectorRegister a, VectorRegister b);
1960   inline void vsrah(    VectorRegister d, VectorRegister a, VectorRegister b);
1961   // Vector Floating-Point not implemented yet
1962   inline void mtvscr(   VectorRegister b);
1963   inline void mfvscr(   VectorRegister d);
1964 
1965   // Vector-Scalar (VSX) instructions.
1966   inline void lxvd2x(   VectorSRegister d, Register a, Register b);
1967   inline void stxvd2x(  VectorSRegister d, Register a, Register b);
1968   inline void mtvrd(    VectorRegister  d, Register a);
1969   inline void mfvrd(    Register        a, VectorRegister d);
1970 
1971   // AES (introduced with Power 8)
1972   inline void vcipher(     VectorRegister d, VectorRegister a, VectorRegister b);
1973   inline void vcipherlast( VectorRegister d, VectorRegister a, VectorRegister b);
1974   inline void vncipher(    VectorRegister d, VectorRegister a, VectorRegister b);
1975   inline void vncipherlast(VectorRegister d, VectorRegister a, VectorRegister b);
1976   inline void vsbox(       VectorRegister d, VectorRegister a);
1977 
1978   // SHA (introduced with Power 8)
1979   // Not yet implemented.
1980 
1981   // Vector Binary Polynomial Multiplication (introduced with Power 8)
1982   inline void vpmsumb(  VectorRegister d, VectorRegister a, VectorRegister b);
1983   inline void vpmsumd(  VectorRegister d, VectorRegister a, VectorRegister b);
1984   inline void vpmsumh(  VectorRegister d, VectorRegister a, VectorRegister b);
1985   inline void vpmsumw(  VectorRegister d, VectorRegister a, VectorRegister b);
1986 
1987   // Vector Permute and Xor (introduced with Power 8)
1988   inline void vpermxor( VectorRegister d, VectorRegister a, VectorRegister b, VectorRegister c);
1989 
1990   // Transactional Memory instructions (introduced with Power 8)
1991   inline void tbegin_();    // R=0
1992   inline void tbeginrot_(); // R=1 Rollback-Only Transaction
1993   inline void tend_();    // A=0
1994   inline void tendall_(); // A=1
1995   inline void tabort_(Register a);
1996   inline void tabortwc_(int t, Register a, Register b);
1997   inline void tabortwci_(int t, Register a, int si);
1998   inline void tabortdc_(int t, Register a, Register b);
1999   inline void tabortdci_(int t, Register a, int si);
2000   inline void tsuspend_(); // tsr with L=0
2001   inline void tresume_();  // tsr with L=1
2002   inline void tcheck(int f);
2003 
2004   // The following encoders use r0 as second operand. These instructions
2005   // read r0 as '0'.
2006   inline void lwzx( Register d, Register s2);
2007   inline void lwz(  Register d, int si16);
2008   inline void lwax( Register d, Register s2);
2009   inline void lwa(  Register d, int si16);
2010   inline void lwbrx(Register d, Register s2);
2011   inline void lhzx( Register d, Register s2);
2012   inline void lhz(  Register d, int si16);
2013   inline void lhax( Register d, Register s2);
2014   inline void lha(  Register d, int si16);
2015   inline void lhbrx(Register d, Register s2);
2016   inline void lbzx( Register d, Register s2);
2017   inline void lbz(  Register d, int si16);
2018   inline void ldx(  Register d, Register s2);
2019   inline void ld(   Register d, int si16);
2020   inline void stwx( Register d, Register s2);
2021   inline void stw(  Register d, int si16);
2022   inline void sthx( Register d, Register s2);
2023   inline void sth(  Register d, int si16);
2024   inline void stbx( Register d, Register s2);
2025   inline void stb(  Register d, int si16);
2026   inline void stdx( Register d, Register s2);
2027   inline void std(  Register d, int si16);
2028 
2029   // PPC 2, section 3.2.1 Instruction Cache Instructions
2030   inline void icbi(    Register s2);
2031   // PPC 2, section 3.2.2 Data Cache Instructions
2032   //inlinevoid dcba(   Register s2); // Instruction for embedded processor only.
2033   inline void dcbz(    Register s2);
2034   inline void dcbst(   Register s2);
2035   inline void dcbf(    Register s2);
2036   // dcache read hint
2037   inline void dcbt(    Register s2);
2038   inline void dcbtct(  Register s2, int ct);
2039   inline void dcbtds(  Register s2, int ds);
2040   // dcache write hint
2041   inline void dcbtst(  Register s2);
2042   inline void dcbtstct(Register s2, int ct);
2043 
2044   // Atomics: use ra0mem to disallow R0 as base.
2045   inline void lwarx_unchecked(Register d, Register b, int eh1);
2046   inline void ldarx_unchecked(Register d, Register b, int eh1);
2047   inline void lqarx_unchecked(Register d, Register b, int eh1);
2048   inline void lwarx( Register d, Register b, bool hint_exclusive_access);
2049   inline void ldarx( Register d, Register b, bool hint_exclusive_access);
2050   inline void lqarx( Register d, Register b, bool hint_exclusive_access);
2051   inline void stwcx_(Register s, Register b);
2052   inline void stdcx_(Register s, Register b);
2053   inline void stqcx_(Register s, Register b);
2054   inline void lfs(   FloatRegister d, int si16);
2055   inline void lfsx(  FloatRegister d, Register b);
2056   inline void lfd(   FloatRegister d, int si16);
2057   inline void lfdx(  FloatRegister d, Register b);
2058   inline void stfs(  FloatRegister s, int si16);
2059   inline void stfsx( FloatRegister s, Register b);
2060   inline void stfd(  FloatRegister s, int si16);
2061   inline void stfdx( FloatRegister s, Register b);
2062   inline void lvebx( VectorRegister d, Register s2);
2063   inline void lvehx( VectorRegister d, Register s2);
2064   inline void lvewx( VectorRegister d, Register s2);
2065   inline void lvx(   VectorRegister d, Register s2);
2066   inline void lvxl(  VectorRegister d, Register s2);
2067   inline void stvebx(VectorRegister d, Register s2);
2068   inline void stvehx(VectorRegister d, Register s2);
2069   inline void stvewx(VectorRegister d, Register s2);
2070   inline void stvx(  VectorRegister d, Register s2);
2071   inline void stvxl( VectorRegister d, Register s2);
2072   inline void lvsl(  VectorRegister d, Register s2);
2073   inline void lvsr(  VectorRegister d, Register s2);
2074 
2075   // RegisterOrConstant versions.
2076   // These emitters choose between the versions using two registers and
2077   // those with register and immediate, depending on the content of roc.
2078   // If the constant is not encodable as immediate, instructions to
2079   // load the constant are emitted beforehand. Store instructions need a
2080   // tmp reg if the constant is not encodable as immediate.
2081   // Size unpredictable.
2082   void ld(  Register d, RegisterOrConstant roc, Register s1 = noreg);
2083   void lwa( Register d, RegisterOrConstant roc, Register s1 = noreg);
2084   void lwz( Register d, RegisterOrConstant roc, Register s1 = noreg);
2085   void lha( Register d, RegisterOrConstant roc, Register s1 = noreg);
2086   void lhz( Register d, RegisterOrConstant roc, Register s1 = noreg);
2087   void lbz( Register d, RegisterOrConstant roc, Register s1 = noreg);
2088   void std( Register d, RegisterOrConstant roc, Register s1 = noreg, Register tmp = noreg);
2089   void stw( Register d, RegisterOrConstant roc, Register s1 = noreg, Register tmp = noreg);
2090   void sth( Register d, RegisterOrConstant roc, Register s1 = noreg, Register tmp = noreg);
2091   void stb( Register d, RegisterOrConstant roc, Register s1 = noreg, Register tmp = noreg);
2092   void add( Register d, RegisterOrConstant roc, Register s1);
2093   void subf(Register d, RegisterOrConstant roc, Register s1);
2094   void cmpd(ConditionRegister d, RegisterOrConstant roc, Register s1);
2095 
2096 
2097   // Emit several instructions to load a 64 bit constant. This issues a fixed
2098   // instruction pattern so that the constant can be patched later on.
2099   enum {
2100     load_const_size = 5 * BytesPerInstWord
2101   };
2102          void load_const(Register d, long a,            Register tmp = noreg);
2103   inline void load_const(Register d, void* a,           Register tmp = noreg);
2104   inline void load_const(Register d, Label& L,          Register tmp = noreg);
2105   inline void load_const(Register d, AddressLiteral& a, Register tmp = noreg);
2106 
2107   // Load a 64 bit constant, optimized, not identifyable.
2108   // Tmp can be used to increase ILP. Set return_simm16_rest = true to get a
2109   // 16 bit immediate offset. This is useful if the offset can be encoded in
2110   // a succeeding instruction.
2111          int load_const_optimized(Register d, long a,  Register tmp = noreg, bool return_simm16_rest = false);
2112   inline int load_const_optimized(Register d, void* a, Register tmp = noreg, bool return_simm16_rest = false) {
2113     return load_const_optimized(d, (long)(unsigned long)a, tmp, return_simm16_rest);
2114   }
2115 
2116   // Creation
2117   Assembler(CodeBuffer* code) : AbstractAssembler(code) {
2118 #ifdef CHECK_DELAY
2119     delay_state = no_delay;
2120 #endif
2121   }
2122 
2123   // Testing
2124 #ifndef PRODUCT
2125   void test_asm();
2126 #endif
2127 };
2128 
2129 
2130 #endif // CPU_PPC_VM_ASSEMBLER_PPC_HPP