tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Constants-arm.h (23570B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      2 * vim: set ts=8 sts=2 et sw=2 tw=80:
      3 */
      4 // Copyright 2011 the V8 project authors. All rights reserved.
      5 // Use of this source code is governed by a BSD-style license that can be
      6 // found in the LICENSE file.
      7 
      8 #ifndef jit_arm_disasm_Constants_arm_h
      9 #define jit_arm_disasm_Constants_arm_h
     10 
     11 #ifdef JS_DISASM_ARM
     12 
     13 #  include "mozilla/Assertions.h"
     14 
     15 #  include <string.h>
     16 
     17 namespace js {
     18 namespace jit {
     19 namespace disasm {
     20 
     21 // Constant pool marker.
     22 // Use UDF, the permanently undefined instruction.
     23 const int kConstantPoolMarkerMask = 0xfff000f0;
     24 const int kConstantPoolMarker = 0xe7f000f0;
     25 const int kConstantPoolLengthMaxMask = 0xffff;
     26 
     27 inline int EncodeConstantPoolLength(int length) {
     28  MOZ_ASSERT((length & kConstantPoolLengthMaxMask) == length);
     29  return ((length & 0xfff0) << 4) | (length & 0xf);
     30 }
     31 
     32 inline int DecodeConstantPoolLength(int instr) {
     33  MOZ_ASSERT((instr & kConstantPoolMarkerMask) == kConstantPoolMarker);
     34  return ((instr >> 4) & 0xfff0) | (instr & 0xf);
     35 }
     36 
     37 // Used in code age prologue - ldr(pc, MemOperand(pc, -4))
     38 const int kCodeAgeJumpInstruction = 0xe51ff004;
     39 
     40 // Number of registers in normal ARM mode.
     41 const int kNumRegisters = 16;
     42 
     43 // VFP support.
     44 const int kNumVFPSingleRegisters = 32;
     45 const int kNumVFPDoubleRegisters = 32;
     46 const int kNumVFPRegisters = kNumVFPSingleRegisters + kNumVFPDoubleRegisters;
     47 
     48 // PC is register 15.
     49 const int kPCRegister = 15;
     50 const int kNoRegister = -1;
     51 
     52 // -----------------------------------------------------------------------------
     53 // Conditions.
     54 
     55 // Defines constants and accessor classes to assemble, disassemble and
     56 // simulate ARM instructions.
     57 //
     58 // Section references in the code refer to the "ARM Architecture Reference
     59 // Manual" from July 2005 (available at http://www.arm.com/miscPDFs/14128.pdf)
     60 //
     61 // Constants for specific fields are defined in their respective named enums.
     62 // General constants are in an anonymous enum in class Instr.
     63 
     64 // Values for the condition field as defined in section A3.2
     65 enum Condition {
     66  kNoCondition = -1,
     67 
     68  eq = 0 << 28,   // Z set            Equal.
     69  ne = 1 << 28,   // Z clear          Not equal.
     70  cs = 2 << 28,   // C set            Unsigned higher or same.
     71  cc = 3 << 28,   // C clear          Unsigned lower.
     72  mi = 4 << 28,   // N set            Negative.
     73  pl = 5 << 28,   // N clear          Positive or zero.
     74  vs = 6 << 28,   // V set            Overflow.
     75  vc = 7 << 28,   // V clear          No overflow.
     76  hi = 8 << 28,   // C set, Z clear   Unsigned higher.
     77  ls = 9 << 28,   // C clear or Z set Unsigned lower or same.
     78  ge = 10 << 28,  // N == V           Greater or equal.
     79  lt = 11 << 28,  // N != V           Less than.
     80  gt = 12 << 28,  // Z clear, N == V  Greater than.
     81  le = 13 << 28,  // Z set or N != V  Less then or equal
     82  al = 14 << 28,  //                  Always.
     83 
     84  kSpecialCondition = 15 << 28,  // Special condition (refer to section A3.2.1).
     85  kNumberOfConditions = 16,
     86 
     87  // Aliases.
     88  hs = cs,  // C set            Unsigned higher or same.
     89  lo = cc   // C clear          Unsigned lower.
     90 };
     91 
     92 inline Condition NegateCondition(Condition cond) {
     93  MOZ_ASSERT(cond != al);
     94  return static_cast<Condition>(cond ^ ne);
     95 }
     96 
     97 // Commute a condition such that {a cond b == b cond' a}.
     98 inline Condition CommuteCondition(Condition cond) {
     99  switch (cond) {
    100    case lo:
    101      return hi;
    102    case hi:
    103      return lo;
    104    case hs:
    105      return ls;
    106    case ls:
    107      return hs;
    108    case lt:
    109      return gt;
    110    case gt:
    111      return lt;
    112    case ge:
    113      return le;
    114    case le:
    115      return ge;
    116    default:
    117      return cond;
    118  }
    119 }
    120 
    121 // -----------------------------------------------------------------------------
    122 // Instructions encoding.
    123 
    124 // Instr is merely used by the Assembler to distinguish 32bit integers
    125 // representing instructions from usual 32 bit values.
    126 // Instruction objects are pointers to 32bit values, and provide methods to
    127 // access the various ISA fields.
    128 typedef int32_t Instr;
    129 
    130 // Opcodes for Data-processing instructions (instructions with a type 0 and 1)
    131 // as defined in section A3.4
    132 enum Opcode {
    133  AND = 0 << 21,   // Logical AND.
    134  EOR = 1 << 21,   // Logical Exclusive OR.
    135  SUB = 2 << 21,   // Subtract.
    136  RSB = 3 << 21,   // Reverse Subtract.
    137  ADD = 4 << 21,   // Add.
    138  ADC = 5 << 21,   // Add with Carry.
    139  SBC = 6 << 21,   // Subtract with Carry.
    140  RSC = 7 << 21,   // Reverse Subtract with Carry.
    141  TST = 8 << 21,   // Test.
    142  TEQ = 9 << 21,   // Test Equivalence.
    143  CMP = 10 << 21,  // Compare.
    144  CMN = 11 << 21,  // Compare Negated.
    145  ORR = 12 << 21,  // Logical (inclusive) OR.
    146  MOV = 13 << 21,  // Move.
    147  BIC = 14 << 21,  // Bit Clear.
    148  MVN = 15 << 21   // Move Not.
    149 };
    150 
    151 // The bits for bit 7-4 for some type 0 miscellaneous instructions.
    152 enum MiscInstructionsBits74 {
    153  // With bits 22-21 01.
    154  BX = 1 << 4,
    155  BXJ = 2 << 4,
    156  BLX = 3 << 4,
    157  BKPT = 7 << 4,
    158 
    159  // With bits 22-21 11.
    160  CLZ = 1 << 4
    161 };
    162 
    163 // Load and store exclusive instructions.
    164 
    165 // Bit positions.
    166 enum {
    167  ExclusiveOpHi = 24,    // Hi bit of opcode field
    168  ExclusiveOpLo = 23,    // Lo bit of opcode field
    169  ExclusiveSizeHi = 22,  // Hi bit of operand size field
    170  ExclusiveSizeLo = 21,  // Lo bit of operand size field
    171  ExclusiveLoad = 20     // Bit indicating load
    172 };
    173 
    174 // Opcode bits for exclusive instructions.
    175 enum { ExclusiveOpcode = 3 };
    176 
    177 // Operand size, Bits(ExclusiveSizeHi,ExclusiveSizeLo).
    178 enum {
    179  ExclusiveWord = 0,
    180  ExclusiveDouble = 1,
    181  ExclusiveByte = 2,
    182  ExclusiveHalf = 3
    183 };
    184 
    185 // Instruction encoding bits and masks.
    186 enum {
    187  H = 1 << 5,   // Halfword (or byte).
    188  S6 = 1 << 6,  // Signed (or unsigned).
    189  L = 1 << 20,  // Load (or store).
    190  S = 1 << 20,  // Set condition code (or leave unchanged).
    191  W = 1 << 21,  // Writeback base register (or leave unchanged).
    192  A = 1 << 21,  // Accumulate in multiply instruction (or not).
    193  B = 1 << 22,  // Unsigned byte (or word).
    194  N = 1 << 22,  // Long (or short).
    195  U = 1 << 23,  // Positive (or negative) offset/index.
    196  P = 1 << 24,  // Offset/pre-indexed addressing (or post-indexed addressing).
    197  I = 1 << 25,  // Immediate shifter operand (or not).
    198  B0 = 1 << 0,
    199  B4 = 1 << 4,
    200  B5 = 1 << 5,
    201  B6 = 1 << 6,
    202  B7 = 1 << 7,
    203  B8 = 1 << 8,
    204  B9 = 1 << 9,
    205  B12 = 1 << 12,
    206  B16 = 1 << 16,
    207  B17 = 1 << 17,
    208  B18 = 1 << 18,
    209  B19 = 1 << 19,
    210  B20 = 1 << 20,
    211  B21 = 1 << 21,
    212  B22 = 1 << 22,
    213  B23 = 1 << 23,
    214  B24 = 1 << 24,
    215  B25 = 1 << 25,
    216  B26 = 1 << 26,
    217  B27 = 1 << 27,
    218  B28 = 1 << 28,
    219 
    220  // Instruction bit masks.
    221  kCondMask = 15 << 28,
    222  kALUMask = 0x6f << 21,
    223  kRdMask = 15 << 12,  // In str instruction.
    224  kCoprocessorMask = 15 << 8,
    225  kOpCodeMask = 15 << 21,  // In data-processing instructions.
    226  kImm24Mask = (1 << 24) - 1,
    227  kImm16Mask = (1 << 16) - 1,
    228  kImm8Mask = (1 << 8) - 1,
    229  kOff12Mask = (1 << 12) - 1,
    230  kOff8Mask = (1 << 8) - 1
    231 };
    232 
    233 // -----------------------------------------------------------------------------
    234 // Addressing modes and instruction variants.
    235 
    236 // Condition code updating mode.
    237 enum SBit {
    238  SetCC = 1 << 20,   // Set condition code.
    239  LeaveCC = 0 << 20  // Leave condition code unchanged.
    240 };
    241 
    242 // Status register selection.
    243 enum SRegister { CPSR = 0 << 22, SPSR = 1 << 22 };
    244 
    245 // Shifter types for Data-processing operands as defined in section A5.1.2.
    246 enum ShiftOp {
    247  LSL = 0 << 5,  // Logical shift left.
    248  LSR = 1 << 5,  // Logical shift right.
    249  ASR = 2 << 5,  // Arithmetic shift right.
    250  ROR = 3 << 5,  // Rotate right.
    251 
    252  // RRX is encoded as ROR with shift_imm == 0.
    253  // Use a special code to make the distinction. The RRX ShiftOp is only used
    254  // as an argument, and will never actually be encoded. The Assembler will
    255  // detect it and emit the correct ROR shift operand with shift_imm == 0.
    256  RRX = -1,
    257  kNumberOfShifts = 4
    258 };
    259 
    260 // Status register fields.
    261 enum SRegisterField {
    262  CPSR_c = CPSR | 1 << 16,
    263  CPSR_x = CPSR | 1 << 17,
    264  CPSR_s = CPSR | 1 << 18,
    265  CPSR_f = CPSR | 1 << 19,
    266  SPSR_c = SPSR | 1 << 16,
    267  SPSR_x = SPSR | 1 << 17,
    268  SPSR_s = SPSR | 1 << 18,
    269  SPSR_f = SPSR | 1 << 19
    270 };
    271 
    272 // Status register field mask (or'ed SRegisterField enum values).
    273 typedef uint32_t SRegisterFieldMask;
    274 
    275 // Memory operand addressing mode.
    276 enum AddrMode {
    277  // Bit encoding P U W.
    278  Offset = (8 | 4 | 0) << 21,     // Offset (without writeback to base).
    279  PreIndex = (8 | 4 | 1) << 21,   // Pre-indexed addressing with writeback.
    280  PostIndex = (0 | 4 | 0) << 21,  // Post-indexed addressing with writeback.
    281  NegOffset =
    282      (8 | 0 | 0) << 21,  // Negative offset (without writeback to base).
    283  NegPreIndex = (8 | 0 | 1) << 21,  // Negative pre-indexed with writeback.
    284  NegPostIndex = (0 | 0 | 0) << 21  // Negative post-indexed with writeback.
    285 };
    286 
    287 // Load/store multiple addressing mode.
    288 enum BlockAddrMode {
    289  // Bit encoding P U W .
    290  da = (0 | 0 | 0) << 21,    // Decrement after.
    291  ia = (0 | 4 | 0) << 21,    // Increment after.
    292  db = (8 | 0 | 0) << 21,    // Decrement before.
    293  ib = (8 | 4 | 0) << 21,    // Increment before.
    294  da_w = (0 | 0 | 1) << 21,  // Decrement after with writeback to base.
    295  ia_w = (0 | 4 | 1) << 21,  // Increment after with writeback to base.
    296  db_w = (8 | 0 | 1) << 21,  // Decrement before with writeback to base.
    297  ib_w = (8 | 4 | 1) << 21,  // Increment before with writeback to base.
    298 
    299  // Alias modes for comparison when writeback does not matter.
    300  da_x = (0 | 0 | 0) << 21,  // Decrement after.
    301  ia_x = (0 | 4 | 0) << 21,  // Increment after.
    302  db_x = (8 | 0 | 0) << 21,  // Decrement before.
    303  ib_x = (8 | 4 | 0) << 21,  // Increment before.
    304 
    305  kBlockAddrModeMask = (8 | 4 | 1) << 21
    306 };
    307 
    308 // Coprocessor load/store operand size.
    309 enum LFlag {
    310  Long = 1 << 22,  // Long load/store coprocessor.
    311  Short = 0 << 22  // Short load/store coprocessor.
    312 };
    313 
    314 // NEON data type
    315 enum NeonDataType {
    316  NeonS8 = 0x1,             // U = 0, imm3 = 0b001
    317  NeonS16 = 0x2,            // U = 0, imm3 = 0b010
    318  NeonS32 = 0x4,            // U = 0, imm3 = 0b100
    319  NeonU8 = 1 << 24 | 0x1,   // U = 1, imm3 = 0b001
    320  NeonU16 = 1 << 24 | 0x2,  // U = 1, imm3 = 0b010
    321  NeonU32 = 1 << 24 | 0x4,  // U = 1, imm3 = 0b100
    322  NeonDataTypeSizeMask = 0x7,
    323  NeonDataTypeUMask = 1 << 24
    324 };
    325 
    326 enum NeonListType { nlt_1 = 0x7, nlt_2 = 0xA, nlt_3 = 0x6, nlt_4 = 0x2 };
    327 
    328 enum NeonSize { Neon8 = 0x0, Neon16 = 0x1, Neon32 = 0x2, Neon64 = 0x3 };
    329 
    330 // -----------------------------------------------------------------------------
    331 // Supervisor Call (svc) specific support.
    332 
    333 // Special Software Interrupt codes when used in the presence of the ARM
    334 // simulator.
    335 // svc (formerly swi) provides a 24bit immediate value. Use bits 22:0 for
    336 // standard SoftwareInterrupCode. Bit 23 is reserved for the stop feature.
    337 enum SoftwareInterruptCodes {
    338  // transition to C code
    339  kCallRtRedirected = 0x10,
    340  // break point
    341  kBreakpoint = 0x20,
    342  // stop
    343  kStopCode = 1 << 23
    344 };
    345 const uint32_t kStopCodeMask = kStopCode - 1;
    346 const uint32_t kMaxStopCode = kStopCode - 1;
    347 const int32_t kDefaultStopCode = -1;
    348 
    349 // Type of VFP register. Determines register encoding.
    350 enum VFPRegPrecision { kSinglePrecision = 0, kDoublePrecision = 1 };
    351 
    352 // VFP FPSCR constants.
    353 enum VFPConversionMode { kFPSCRRounding = 0, kDefaultRoundToZero = 1 };
    354 
    355 // This mask does not include the "inexact" or "input denormal" cumulative
    356 // exceptions flags, because we usually don't want to check for it.
    357 const uint32_t kVFPExceptionMask = 0xf;
    358 const uint32_t kVFPInvalidOpExceptionBit = 1 << 0;
    359 const uint32_t kVFPOverflowExceptionBit = 1 << 2;
    360 const uint32_t kVFPUnderflowExceptionBit = 1 << 3;
    361 const uint32_t kVFPInexactExceptionBit = 1 << 4;
    362 const uint32_t kVFPFlushToZeroMask = 1 << 24;
    363 const uint32_t kVFPDefaultNaNModeControlBit = 1 << 25;
    364 
    365 const uint32_t kVFPNConditionFlagBit = 1 << 31;
    366 const uint32_t kVFPZConditionFlagBit = 1 << 30;
    367 const uint32_t kVFPCConditionFlagBit = 1 << 29;
    368 const uint32_t kVFPVConditionFlagBit = 1 << 28;
    369 
    370 // VFP rounding modes. See ARM DDI 0406B Page A2-29.
    371 enum VFPRoundingMode {
    372  RN = 0 << 22,  // Round to Nearest.
    373  RP = 1 << 22,  // Round towards Plus Infinity.
    374  RM = 2 << 22,  // Round towards Minus Infinity.
    375  RZ = 3 << 22,  // Round towards zero.
    376 
    377  // Aliases.
    378  kRoundToNearest = RN,
    379  kRoundToPlusInf = RP,
    380  kRoundToMinusInf = RM,
    381  kRoundToZero = RZ
    382 };
    383 
    384 const uint32_t kVFPRoundingModeMask = 3 << 22;
    385 
    386 enum CheckForInexactConversion {
    387  kCheckForInexactConversion,
    388  kDontCheckForInexactConversion
    389 };
    390 
    391 // -----------------------------------------------------------------------------
    392 // Hints.
    393 
    394 // Branch hints are not used on the ARM.  They are defined so that they can
    395 // appear in shared function signatures, but will be ignored in ARM
    396 // implementations.
    397 enum Hint { no_hint };
    398 
    399 // Hints are not used on the arm.  Negating is trivial.
    400 inline Hint NegateHint(Hint ignored) { return no_hint; }
    401 
    402 // -----------------------------------------------------------------------------
    403 // Instruction abstraction.
    404 
    405 // The class Instruction enables access to individual fields defined in the ARM
    406 // architecture instruction set encoding as described in figure A3-1.
    407 // Note that the Assembler uses typedef int32_t Instr.
    408 //
    409 // Example: Test whether the instruction at ptr does set the condition code
    410 // bits.
    411 //
    412 // bool InstructionSetsConditionCodes(byte* ptr) {
    413 //   Instruction* instr = Instruction::At(ptr);
    414 //   int type = instr->TypeValue();
    415 //   return ((type == 0) || (type == 1)) && instr->HasS();
    416 // }
    417 //
    418 class Instruction {
    419 public:
    420  enum { kInstrSize = 4, kInstrSizeLog2 = 2, kPCReadOffset = 8 };
    421 
    422  // Helper macro to define static accessors.
    423  // We use the cast to char* trick to bypass the strict anti-aliasing rules.
    424 #  define DECLARE_STATIC_TYPED_ACCESSOR(return_type, Name) \
    425    static inline return_type Name(Instr instr) {          \
    426      char* temp = reinterpret_cast<char*>(&instr);        \
    427      return reinterpret_cast<Instruction*>(temp)->Name(); \
    428    }
    429 
    430 #  define DECLARE_STATIC_ACCESSOR(Name) DECLARE_STATIC_TYPED_ACCESSOR(int, Name)
    431 
    432  // Get the raw instruction bits.
    433  inline Instr InstructionBits() const {
    434    return *reinterpret_cast<const Instr*>(this);
    435  }
    436 
    437  // Set the raw instruction bits to value.
    438  inline void SetInstructionBits(Instr value) {
    439    *reinterpret_cast<Instr*>(this) = value;
    440  }
    441 
    442  // Read one particular bit out of the instruction bits.
    443  inline int Bit(int nr) const { return (InstructionBits() >> nr) & 1; }
    444 
    445  // Read a bit field's value out of the instruction bits.
    446  inline int Bits(int hi, int lo) const {
    447    return (InstructionBits() >> lo) & ((2 << (hi - lo)) - 1);
    448  }
    449 
    450  // Read a bit field out of the instruction bits.
    451  inline int BitField(int hi, int lo) const {
    452    return InstructionBits() & (((2 << (hi - lo)) - 1) << lo);
    453  }
    454 
    455  // Static support.
    456 
    457  // Read one particular bit out of the instruction bits.
    458  static inline int Bit(Instr instr, int nr) { return (instr >> nr) & 1; }
    459 
    460  // Read the value of a bit field out of the instruction bits.
    461  static inline int Bits(Instr instr, int hi, int lo) {
    462    return (instr >> lo) & ((2 << (hi - lo)) - 1);
    463  }
    464 
    465  // Read a bit field out of the instruction bits.
    466  static inline int BitField(Instr instr, int hi, int lo) {
    467    return instr & (((2 << (hi - lo)) - 1) << lo);
    468  }
    469 
    470  // Accessors for the different named fields used in the ARM encoding.
    471  // The naming of these accessor corresponds to figure A3-1.
    472  //
    473  // Two kind of accessors are declared:
    474  // - <Name>Field() will return the raw field, i.e. the field's bits at their
    475  //   original place in the instruction encoding.
    476  //   e.g. if instr is the 'addgt r0, r1, r2' instruction, encoded as
    477  //   0xC0810002 ConditionField(instr) will return 0xC0000000.
    478  // - <Name>Value() will return the field value, shifted back to bit 0.
    479  //   e.g. if instr is the 'addgt r0, r1, r2' instruction, encoded as
    480  //   0xC0810002 ConditionField(instr) will return 0xC.
    481 
    482  // Generally applicable fields
    483  inline Condition ConditionValue() const {
    484    return static_cast<Condition>(Bits(31, 28));
    485  }
    486  inline Condition ConditionField() const {
    487    return static_cast<Condition>(BitField(31, 28));
    488  }
    489  DECLARE_STATIC_TYPED_ACCESSOR(Condition, ConditionValue);
    490  DECLARE_STATIC_TYPED_ACCESSOR(Condition, ConditionField);
    491 
    492  inline int TypeValue() const { return Bits(27, 25); }
    493  inline int SpecialValue() const { return Bits(27, 23); }
    494 
    495  inline int RnValue() const { return Bits(19, 16); }
    496  DECLARE_STATIC_ACCESSOR(RnValue);
    497  inline int RdValue() const { return Bits(15, 12); }
    498  DECLARE_STATIC_ACCESSOR(RdValue);
    499 
    500  inline int CoprocessorValue() const { return Bits(11, 8); }
    501  // Support for VFP.
    502  // Vn(19-16) | Vd(15-12) |  Vm(3-0)
    503  inline int VnValue() const { return Bits(19, 16); }
    504  inline int VmValue() const { return Bits(3, 0); }
    505  inline int VdValue() const { return Bits(15, 12); }
    506  inline int NValue() const { return Bit(7); }
    507  inline int MValue() const { return Bit(5); }
    508  inline int DValue() const { return Bit(22); }
    509  inline int RtValue() const { return Bits(15, 12); }
    510  inline int PValue() const { return Bit(24); }
    511  inline int UValue() const { return Bit(23); }
    512  inline int Opc1Value() const { return (Bit(23) << 2) | Bits(21, 20); }
    513  inline int Opc2Value() const { return Bits(19, 16); }
    514  inline int Opc3Value() const { return Bits(7, 6); }
    515  inline int SzValue() const { return Bit(8); }
    516  inline int VLValue() const { return Bit(20); }
    517  inline int VCValue() const { return Bit(8); }
    518  inline int VAValue() const { return Bits(23, 21); }
    519  inline int VBValue() const { return Bits(6, 5); }
    520  inline int VFPNRegValue(VFPRegPrecision pre) {
    521    return VFPGlueRegValue(pre, 16, 7);
    522  }
    523  inline int VFPMRegValue(VFPRegPrecision pre) {
    524    return VFPGlueRegValue(pre, 0, 5);
    525  }
    526  inline int VFPDRegValue(VFPRegPrecision pre) {
    527    return VFPGlueRegValue(pre, 12, 22);
    528  }
    529 
    530  // Fields used in Data processing instructions
    531  inline int OpcodeValue() const { return static_cast<Opcode>(Bits(24, 21)); }
    532  inline Opcode OpcodeField() const {
    533    return static_cast<Opcode>(BitField(24, 21));
    534  }
    535  inline int SValue() const { return Bit(20); }
    536  // with register
    537  inline int RmValue() const { return Bits(3, 0); }
    538  DECLARE_STATIC_ACCESSOR(RmValue);
    539  inline int ShiftValue() const { return static_cast<ShiftOp>(Bits(6, 5)); }
    540  inline ShiftOp ShiftField() const {
    541    return static_cast<ShiftOp>(BitField(6, 5));
    542  }
    543  inline int RegShiftValue() const { return Bit(4); }
    544  inline int RsValue() const { return Bits(11, 8); }
    545  inline int ShiftAmountValue() const { return Bits(11, 7); }
    546  // with immediate
    547  inline int RotateValue() const { return Bits(11, 8); }
    548  DECLARE_STATIC_ACCESSOR(RotateValue);
    549  inline int Immed8Value() const { return Bits(7, 0); }
    550  DECLARE_STATIC_ACCESSOR(Immed8Value);
    551  inline int Immed4Value() const { return Bits(19, 16); }
    552  inline int ImmedMovwMovtValue() const {
    553    return Immed4Value() << 12 | Offset12Value();
    554  }
    555  DECLARE_STATIC_ACCESSOR(ImmedMovwMovtValue);
    556 
    557  // Fields used in Load/Store instructions
    558  inline int PUValue() const { return Bits(24, 23); }
    559  inline int PUField() const { return BitField(24, 23); }
    560  inline int BValue() const { return Bit(22); }
    561  inline int WValue() const { return Bit(21); }
    562  inline int LValue() const { return Bit(20); }
    563  // with register uses same fields as Data processing instructions above
    564  // with immediate
    565  inline int Offset12Value() const { return Bits(11, 0); }
    566  // multiple
    567  inline int RlistValue() const { return Bits(15, 0); }
    568  // extra loads and stores
    569  inline int SignValue() const { return Bit(6); }
    570  inline int HValue() const { return Bit(5); }
    571  inline int ImmedHValue() const { return Bits(11, 8); }
    572  inline int ImmedLValue() const { return Bits(3, 0); }
    573 
    574  // Fields used in Branch instructions
    575  inline int LinkValue() const { return Bit(24); }
    576  inline int SImmed24Value() const { return ((InstructionBits() << 8) >> 8); }
    577 
    578  // Fields used in Software interrupt instructions
    579  inline SoftwareInterruptCodes SvcValue() const {
    580    return static_cast<SoftwareInterruptCodes>(Bits(23, 0));
    581  }
    582 
    583  // Test for special encodings of type 0 instructions (extra loads and stores,
    584  // as well as multiplications).
    585  inline bool IsSpecialType0() const { return (Bit(7) == 1) && (Bit(4) == 1); }
    586 
    587  // Test for miscellaneous instructions encodings of type 0 instructions.
    588  inline bool IsMiscType0() const {
    589    return (Bit(24) == 1) && (Bit(23) == 0) && (Bit(20) == 0) &&
    590           ((Bit(7) == 0));
    591  }
    592 
    593  // Test for a nop instruction, which falls under type 1.
    594  inline bool IsNopType1() const { return Bits(24, 0) == 0x0120F000; }
    595 
    596  // Test for a yield instruction, which falls under type 1.
    597  inline bool IsYieldType1() const { return Bits(24, 0) == 0x0120F001; }
    598 
    599  // Test for a nop instruction, which falls under type 1.
    600  inline bool IsCsdbType1() const { return Bits(24, 0) == 0x0120F014; }
    601 
    602  // Test for a stop instruction.
    603  inline bool IsStop() const {
    604    return (TypeValue() == 7) && (Bit(24) == 1) && (SvcValue() >= kStopCode);
    605  }
    606 
    607  // Special accessors that test for existence of a value.
    608  inline bool HasS() const { return SValue() == 1; }
    609  inline bool HasB() const { return BValue() == 1; }
    610  inline bool HasW() const { return WValue() == 1; }
    611  inline bool HasL() const { return LValue() == 1; }
    612  inline bool HasU() const { return UValue() == 1; }
    613  inline bool HasSign() const { return SignValue() == 1; }
    614  inline bool HasH() const { return HValue() == 1; }
    615  inline bool HasLink() const { return LinkValue() == 1; }
    616 
    617  // Decoding the double immediate in the vmov instruction.
    618  double DoubleImmedVmov() const;
    619 
    620  // Instructions are read of out a code stream. The only way to get a
    621  // reference to an instruction is to convert a pointer. There is no way
    622  // to allocate or create instances of class Instruction.
    623  // Use the At(pc) function to create references to Instruction.
    624  static Instruction* At(uint8_t* pc) {
    625    return reinterpret_cast<Instruction*>(pc);
    626  }
    627 
    628 private:
    629  // Join split register codes, depending on single or double precision.
    630  // four_bit is the position of the least-significant bit of the four
    631  // bit specifier. one_bit is the position of the additional single bit
    632  // specifier.
    633  inline int VFPGlueRegValue(VFPRegPrecision pre, int four_bit, int one_bit) {
    634    if (pre == kSinglePrecision) {
    635      return (Bits(four_bit + 3, four_bit) << 1) | Bit(one_bit);
    636    }
    637    return (Bit(one_bit) << 4) | Bits(four_bit + 3, four_bit);
    638  }
    639 
    640  // We need to prevent the creation of instances of class Instruction.
    641  Instruction() = delete;
    642  Instruction(const Instruction&) = delete;
    643  void operator=(const Instruction&) = delete;
    644 };
    645 
    646 // Helper functions for converting between register numbers and names.
    647 class Registers {
    648 public:
    649  // Return the name of the register.
    650  static const char* Name(int reg);
    651 
    652  // Lookup the register number for the name provided.
    653  static int Number(const char* name);
    654 
    655  struct RegisterAlias {
    656    int reg;
    657    const char* name;
    658  };
    659 
    660 private:
    661  static const char* names_[kNumRegisters];
    662  static const RegisterAlias aliases_[];
    663 };
    664 
    665 // Helper functions for converting between VFP register numbers and names.
    666 class VFPRegisters {
    667 public:
    668  // Return the name of the register.
    669  static const char* Name(int reg, bool is_double);
    670 
    671  // Lookup the register number for the name provided.
    672  // Set flag pointed by is_double to true if register
    673  // is double-precision.
    674  static int Number(const char* name, bool* is_double);
    675 
    676 private:
    677  static const char* names_[kNumVFPRegisters];
    678 };
    679 
    680 }  // namespace disasm
    681 }  // namespace jit
    682 }  // namespace js
    683 
    684 #endif  // JS_DISASM_ARM
    685 
    686 #endif  // jit_arm_disasm_Constants_arm_h