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