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