2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 University of Szeged
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #ifndef ARMAssembler_h
28 #define ARMAssembler_h
30 #if ENABLE(ASSEMBLER) && CPU(ARM_THUMB2)
32 #include "AssemblerBuffer.h"
33 #include <wtf/Assertions.h>
34 #include <wtf/Vector.h>
39 namespace ARMRegisters
{
48 r7
, wr
= r7
, // thumb work register
50 r9
, sb
= r9
, // static base
51 r10
, sl
= r10
, // stack limit
52 r11
, fp
= r11
, // frame pointer
127 } FPDoubleRegisterID
;
164 inline FPSingleRegisterID
asSingle(FPDoubleRegisterID reg
)
167 return (FPSingleRegisterID
)(reg
<< 1);
170 inline FPDoubleRegisterID
asDouble(FPSingleRegisterID reg
)
173 return (FPDoubleRegisterID
)(reg
>> 1);
177 class ARMv7Assembler
;
178 class ARMThumbImmediate
{
179 friend class ARMv7Assembler
;
181 typedef uint8_t ThumbImmediateType
;
182 static const ThumbImmediateType TypeInvalid
= 0;
183 static const ThumbImmediateType TypeEncoded
= 1;
184 static const ThumbImmediateType TypeUInt16
= 2;
194 // If this is an encoded immediate, then it may describe a shift, or a pattern.
196 unsigned shiftValue7
: 7;
197 unsigned shiftAmount
: 5;
200 unsigned immediate
: 8;
201 unsigned pattern
: 4;
203 } ThumbImmediateValue
;
205 // byte0 contains least significant bit; not using an array to make client code endian agnostic.
216 ALWAYS_INLINE
static void countLeadingZerosPartial(uint32_t& value
, int32_t& zeros
, const int N
)
218 if (value
& ~((1 << N
) - 1)) /* check for any of the top N bits (of 2N bits) are set */
219 value
>>= N
; /* if any were set, lose the bottom N */
220 else /* if none of the top N bits are set, */
221 zeros
+= N
; /* then we have identified N leading zeros */
224 static int32_t countLeadingZeros(uint32_t value
)
230 countLeadingZerosPartial(value
, zeros
, 16);
231 countLeadingZerosPartial(value
, zeros
, 8);
232 countLeadingZerosPartial(value
, zeros
, 4);
233 countLeadingZerosPartial(value
, zeros
, 2);
234 countLeadingZerosPartial(value
, zeros
, 1);
239 : m_type(TypeInvalid
)
244 ARMThumbImmediate(ThumbImmediateType type
, ThumbImmediateValue value
)
250 ARMThumbImmediate(ThumbImmediateType type
, uint16_t value
)
253 // Make sure this constructor is only reached with type TypeUInt16;
254 // this extra parameter makes the code a little clearer by making it
255 // explicit at call sites which type is being constructed
256 ASSERT_UNUSED(type
, type
== TypeUInt16
);
258 m_value
.asInt
= value
;
262 static ARMThumbImmediate
makeEncodedImm(uint32_t value
)
264 ThumbImmediateValue encoding
;
267 // okay, these are easy.
269 encoding
.immediate
= value
;
270 encoding
.pattern
= 0;
271 return ARMThumbImmediate(TypeEncoded
, encoding
);
274 int32_t leadingZeros
= countLeadingZeros(value
);
275 // if there were 24 or more leading zeros, then we'd have hit the (value < 256) case.
276 ASSERT(leadingZeros
< 24);
278 // Given a number with bit fields Z:B:C, where count(Z)+count(B)+count(C) == 32,
279 // Z are the bits known zero, B is the 8-bit immediate, C are the bits to check for
280 // zero. count(B) == 8, so the count of bits to be checked is 24 - count(Z).
281 int32_t rightShiftAmount
= 24 - leadingZeros
;
282 if (value
== ((value
>> rightShiftAmount
) << rightShiftAmount
)) {
283 // Shift the value down to the low byte position. The assign to
284 // shiftValue7 drops the implicit top bit.
285 encoding
.shiftValue7
= value
>> rightShiftAmount
;
286 // The endoded shift amount is the magnitude of a right rotate.
287 encoding
.shiftAmount
= 8 + leadingZeros
;
288 return ARMThumbImmediate(TypeEncoded
, encoding
);
294 if ((bytes
.byte0
== bytes
.byte1
) && (bytes
.byte0
== bytes
.byte2
) && (bytes
.byte0
== bytes
.byte3
)) {
295 encoding
.immediate
= bytes
.byte0
;
296 encoding
.pattern
= 3;
297 return ARMThumbImmediate(TypeEncoded
, encoding
);
300 if ((bytes
.byte0
== bytes
.byte2
) && !(bytes
.byte1
| bytes
.byte3
)) {
301 encoding
.immediate
= bytes
.byte0
;
302 encoding
.pattern
= 1;
303 return ARMThumbImmediate(TypeEncoded
, encoding
);
306 if ((bytes
.byte1
== bytes
.byte3
) && !(bytes
.byte0
| bytes
.byte2
)) {
307 encoding
.immediate
= bytes
.byte0
;
308 encoding
.pattern
= 2;
309 return ARMThumbImmediate(TypeEncoded
, encoding
);
312 return ARMThumbImmediate();
315 static ARMThumbImmediate
makeUInt12(int32_t value
)
317 return (!(value
& 0xfffff000))
318 ? ARMThumbImmediate(TypeUInt16
, (uint16_t)value
)
319 : ARMThumbImmediate();
322 static ARMThumbImmediate
makeUInt12OrEncodedImm(int32_t value
)
324 // If this is not a 12-bit unsigned it, try making an encoded immediate.
325 return (!(value
& 0xfffff000))
326 ? ARMThumbImmediate(TypeUInt16
, (uint16_t)value
)
327 : makeEncodedImm(value
);
330 // The 'make' methods, above, return a !isValid() value if the argument
331 // cannot be represented as the requested type. This methods is called
332 // 'get' since the argument can always be represented.
333 static ARMThumbImmediate
makeUInt16(uint16_t value
)
335 return ARMThumbImmediate(TypeUInt16
, value
);
340 return m_type
!= TypeInvalid
;
343 // These methods rely on the format of encoded byte values.
344 bool isUInt3() { return !(m_value
.asInt
& 0xfff8); }
345 bool isUInt4() { return !(m_value
.asInt
& 0xfff0); }
346 bool isUInt5() { return !(m_value
.asInt
& 0xffe0); }
347 bool isUInt6() { return !(m_value
.asInt
& 0xffc0); }
348 bool isUInt7() { return !(m_value
.asInt
& 0xff80); }
349 bool isUInt8() { return !(m_value
.asInt
& 0xff00); }
350 bool isUInt9() { return (m_type
== TypeUInt16
) && !(m_value
.asInt
& 0xfe00); }
351 bool isUInt10() { return (m_type
== TypeUInt16
) && !(m_value
.asInt
& 0xfc00); }
352 bool isUInt12() { return (m_type
== TypeUInt16
) && !(m_value
.asInt
& 0xf000); }
353 bool isUInt16() { return m_type
== TypeUInt16
; }
354 uint8_t getUInt3() { ASSERT(isUInt3()); return m_value
.asInt
; }
355 uint8_t getUInt4() { ASSERT(isUInt4()); return m_value
.asInt
; }
356 uint8_t getUInt5() { ASSERT(isUInt5()); return m_value
.asInt
; }
357 uint8_t getUInt6() { ASSERT(isUInt6()); return m_value
.asInt
; }
358 uint8_t getUInt7() { ASSERT(isUInt7()); return m_value
.asInt
; }
359 uint8_t getUInt8() { ASSERT(isUInt8()); return m_value
.asInt
; }
360 uint8_t getUInt9() { ASSERT(isUInt9()); return m_value
.asInt
; }
361 uint8_t getUInt10() { ASSERT(isUInt10()); return m_value
.asInt
; }
362 uint16_t getUInt12() { ASSERT(isUInt12()); return m_value
.asInt
; }
363 uint16_t getUInt16() { ASSERT(isUInt16()); return m_value
.asInt
; }
365 bool isEncodedImm() { return m_type
== TypeEncoded
; }
368 ThumbImmediateType m_type
;
369 ThumbImmediateValue m_value
;
374 VFPImmediate(double d
)
384 int sign
= static_cast<int>(u
.i
>> 63);
385 int exponent
= static_cast<int>(u
.i
>> 52) & 0x7ff;
386 uint64_t mantissa
= u
.i
& 0x000fffffffffffffull
;
388 if ((exponent
>= 0x3fc) && (exponent
<= 0x403) && !(mantissa
& 0x0000ffffffffffffull
))
389 m_value
= (sign
<< 7) | ((exponent
& 7) << 4) | (int)(mantissa
>> 48);
394 return m_value
!= -1;
399 return (uint8_t)m_value
;
412 SRType_RRX
= SRType_ROR
415 class ARMv7Assembler
;
416 class ShiftTypeAndAmount
{
417 friend class ARMv7Assembler
;
422 m_u
.type
= (ARMShiftType
)0;
426 ShiftTypeAndAmount(ARMShiftType type
, unsigned amount
)
429 m_u
.amount
= amount
& 31;
432 unsigned lo4() { return m_u
.lo4
; }
433 unsigned hi4() { return m_u
.hi4
; }
449 class ARMv7Assembler
{
453 ASSERT(m_jumpsToLink
.isEmpty());
456 typedef ARMRegisters::RegisterID RegisterID
;
457 typedef ARMRegisters::FPSingleRegisterID FPSingleRegisterID
;
458 typedef ARMRegisters::FPDoubleRegisterID FPDoubleRegisterID
;
459 typedef ARMRegisters::FPQuadRegisterID FPQuadRegisterID
;
461 // (HS, LO, HI, LS) -> (AE, B, A, BE)
462 // (VS, VC) -> (O, NO)
480 ConditionCS
= ConditionHS
,
481 ConditionCC
= ConditionLO
,
485 friend class ARMv7Assembler
;
486 friend class ARMInstructionFormatter
;
503 friend class ARMv7Assembler
;
504 friend class ARMInstructionFormatter
;
512 bool isUsed() const { return m_used
; }
513 void used() { m_used
= true; }
519 ASSERT(m_offset
== offset
);
529 LinkRecord(intptr_t from
, intptr_t to
)
540 bool BadReg(RegisterID reg
)
542 return (reg
== ARMRegisters::sp
) || (reg
== ARMRegisters::pc
);
545 uint32_t singleRegisterMask(FPSingleRegisterID rdNum
, int highBitsShift
, int lowBitShift
)
547 uint32_t rdMask
= (rdNum
>> 1) << highBitsShift
;
549 rdMask
|= 1 << lowBitShift
;
553 uint32_t doubleRegisterMask(FPDoubleRegisterID rdNum
, int highBitShift
, int lowBitsShift
)
555 uint32_t rdMask
= (rdNum
& 0xf) << lowBitsShift
;
557 rdMask
|= 1 << highBitShift
;
562 OP_ADD_reg_T1
= 0x1800,
563 OP_SUB_reg_T1
= 0x1A00,
564 OP_ADD_imm_T1
= 0x1C00,
565 OP_SUB_imm_T1
= 0x1E00,
566 OP_MOV_imm_T1
= 0x2000,
567 OP_CMP_imm_T1
= 0x2800,
568 OP_ADD_imm_T2
= 0x3000,
569 OP_SUB_imm_T2
= 0x3800,
570 OP_AND_reg_T1
= 0x4000,
571 OP_EOR_reg_T1
= 0x4040,
572 OP_TST_reg_T1
= 0x4200,
573 OP_RSB_imm_T1
= 0x4240,
574 OP_CMP_reg_T1
= 0x4280,
575 OP_ORR_reg_T1
= 0x4300,
576 OP_MVN_reg_T1
= 0x43C0,
577 OP_ADD_reg_T2
= 0x4400,
578 OP_MOV_reg_T1
= 0x4600,
581 OP_STR_reg_T1
= 0x5000,
582 OP_LDR_reg_T1
= 0x5800,
583 OP_LDRH_reg_T1
= 0x5A00,
584 OP_LDRB_reg_T1
= 0x5C00,
585 OP_STR_imm_T1
= 0x6000,
586 OP_LDR_imm_T1
= 0x6800,
587 OP_LDRB_imm_T1
= 0x7800,
588 OP_LDRH_imm_T1
= 0x8800,
589 OP_STR_imm_T2
= 0x9000,
590 OP_LDR_imm_T2
= 0x9800,
591 OP_ADD_SP_imm_T1
= 0xA800,
592 OP_ADD_SP_imm_T2
= 0xB000,
593 OP_SUB_SP_imm_T1
= 0xB080,
600 OP_AND_reg_T2
= 0xEA00,
601 OP_TST_reg_T2
= 0xEA10,
602 OP_ORR_reg_T2
= 0xEA40,
603 OP_ORR_S_reg_T2
= 0xEA50,
604 OP_ASR_imm_T1
= 0xEA4F,
605 OP_LSL_imm_T1
= 0xEA4F,
606 OP_LSR_imm_T1
= 0xEA4F,
607 OP_ROR_imm_T1
= 0xEA4F,
608 OP_MVN_reg_T2
= 0xEA6F,
609 OP_EOR_reg_T2
= 0xEA80,
610 OP_ADD_reg_T3
= 0xEB00,
611 OP_ADD_S_reg_T3
= 0xEB10,
612 OP_SUB_reg_T2
= 0xEBA0,
613 OP_SUB_S_reg_T2
= 0xEBB0,
614 OP_CMP_reg_T2
= 0xEBB0,
617 OP_VMOV_StoC
= 0xEE00,
618 OP_VMOV_CtoS
= 0xEE10,
624 OP_VCVT_FPIVFP
= 0xEEB0,
625 OP_VMOV_IMM_T2
= 0xEEB0,
628 OP_AND_imm_T1
= 0xF000,
630 OP_ORR_imm_T1
= 0xF040,
631 OP_MOV_imm_T2
= 0xF040,
633 OP_EOR_imm_T1
= 0xF080,
634 OP_ADD_imm_T3
= 0xF100,
635 OP_ADD_S_imm_T3
= 0xF110,
637 OP_SUB_imm_T3
= 0xF1A0,
638 OP_SUB_S_imm_T3
= 0xF1B0,
639 OP_CMP_imm_T2
= 0xF1B0,
640 OP_RSB_imm_T2
= 0xF1C0,
641 OP_ADD_imm_T4
= 0xF200,
642 OP_MOV_imm_T3
= 0xF240,
643 OP_SUB_imm_T4
= 0xF2A0,
646 OP_LDRB_imm_T3
= 0xF810,
647 OP_LDRB_reg_T2
= 0xF810,
648 OP_LDRH_reg_T2
= 0xF830,
649 OP_LDRH_imm_T3
= 0xF830,
650 OP_STR_imm_T4
= 0xF840,
651 OP_STR_reg_T2
= 0xF840,
652 OP_LDR_imm_T4
= 0xF850,
653 OP_LDR_reg_T2
= 0xF850,
654 OP_LDRB_imm_T2
= 0xF890,
655 OP_LDRH_imm_T2
= 0xF8B0,
656 OP_STR_imm_T3
= 0xF8C0,
657 OP_LDR_imm_T3
= 0xF8D0,
658 OP_LSL_reg_T2
= 0xFA00,
659 OP_LSR_reg_T2
= 0xFA20,
660 OP_ASR_reg_T2
= 0xFA40,
661 OP_ROR_reg_T2
= 0xFA60,
662 OP_SMULL_T1
= 0xFB80,
666 OP_VADD_T2b
= 0x0A00,
669 OP_VMOV_IMM_T2b
= 0x0A00,
670 OP_VMUL_T2b
= 0x0A00,
672 OP_VMOV_CtoSb
= 0x0A10,
673 OP_VMOV_StoCb
= 0x0A10,
675 OP_VCMP_T1b
= 0x0A40,
676 OP_VCVT_FPIVFPb
= 0x0A40,
677 OP_VSUB_T2b
= 0x0A40,
683 FourFours(unsigned f3
, unsigned f2
, unsigned f1
, unsigned f0
)
702 class ARMInstructionFormatter
;
705 bool ifThenElseConditionBit(Condition condition
, bool isIf
)
707 return isIf
? (condition
& 1) : !(condition
& 1);
709 uint8_t ifThenElse(Condition condition
, bool inst2if
, bool inst3if
, bool inst4if
)
711 int mask
= (ifThenElseConditionBit(condition
, inst2if
) << 3)
712 | (ifThenElseConditionBit(condition
, inst3if
) << 2)
713 | (ifThenElseConditionBit(condition
, inst4if
) << 1)
715 ASSERT((condition
!= ConditionAL
) || (mask
& (mask
- 1)));
716 return (condition
<< 4) | mask
;
718 uint8_t ifThenElse(Condition condition
, bool inst2if
, bool inst3if
)
720 int mask
= (ifThenElseConditionBit(condition
, inst2if
) << 3)
721 | (ifThenElseConditionBit(condition
, inst3if
) << 2)
723 ASSERT((condition
!= ConditionAL
) || (mask
& (mask
- 1)));
724 return (condition
<< 4) | mask
;
726 uint8_t ifThenElse(Condition condition
, bool inst2if
)
728 int mask
= (ifThenElseConditionBit(condition
, inst2if
) << 3)
730 ASSERT((condition
!= ConditionAL
) || (mask
& (mask
- 1)));
731 return (condition
<< 4) | mask
;
734 uint8_t ifThenElse(Condition condition
)
737 ASSERT((condition
!= ConditionAL
) || (mask
& (mask
- 1)));
738 return (condition
<< 4) | mask
;
743 void add(RegisterID rd
, RegisterID rn
, ARMThumbImmediate imm
)
745 // Rd can only be SP if Rn is also SP.
746 ASSERT((rd
!= ARMRegisters::sp
) || (rn
== ARMRegisters::sp
));
747 ASSERT(rd
!= ARMRegisters::pc
);
748 ASSERT(rn
!= ARMRegisters::pc
);
749 ASSERT(imm
.isValid());
751 if (rn
== ARMRegisters::sp
) {
752 if (!(rd
& 8) && imm
.isUInt10()) {
753 m_formatter
.oneWordOp5Reg3Imm8(OP_ADD_SP_imm_T1
, rd
, imm
.getUInt10() >> 2);
755 } else if ((rd
== ARMRegisters::sp
) && imm
.isUInt9()) {
756 m_formatter
.oneWordOp9Imm7(OP_ADD_SP_imm_T2
, imm
.getUInt9() >> 2);
759 } else if (!((rd
| rn
) & 8)) {
761 m_formatter
.oneWordOp7Reg3Reg3Reg3(OP_ADD_imm_T1
, (RegisterID
)imm
.getUInt3(), rn
, rd
);
763 } else if ((rd
== rn
) && imm
.isUInt8()) {
764 m_formatter
.oneWordOp5Reg3Imm8(OP_ADD_imm_T2
, rd
, imm
.getUInt8());
769 if (imm
.isEncodedImm())
770 m_formatter
.twoWordOp5i6Imm4Reg4EncodedImm(OP_ADD_imm_T3
, rn
, rd
, imm
);
772 ASSERT(imm
.isUInt12());
773 m_formatter
.twoWordOp5i6Imm4Reg4EncodedImm(OP_ADD_imm_T4
, rn
, rd
, imm
);
777 void add(RegisterID rd
, RegisterID rn
, RegisterID rm
, ShiftTypeAndAmount shift
)
779 ASSERT((rd
!= ARMRegisters::sp
) || (rn
== ARMRegisters::sp
));
780 ASSERT(rd
!= ARMRegisters::pc
);
781 ASSERT(rn
!= ARMRegisters::pc
);
783 m_formatter
.twoWordOp12Reg4FourFours(OP_ADD_reg_T3
, rn
, FourFours(shift
.hi4(), rd
, shift
.lo4(), rm
));
786 // NOTE: In an IT block, add doesn't modify the flags register.
787 void add(RegisterID rd
, RegisterID rn
, RegisterID rm
)
790 m_formatter
.oneWordOp8RegReg143(OP_ADD_reg_T2
, rm
, rd
);
792 m_formatter
.oneWordOp8RegReg143(OP_ADD_reg_T2
, rn
, rd
);
793 else if (!((rd
| rn
| rm
) & 8))
794 m_formatter
.oneWordOp7Reg3Reg3Reg3(OP_ADD_reg_T1
, rm
, rn
, rd
);
796 add(rd
, rn
, rm
, ShiftTypeAndAmount());
799 // Not allowed in an IT (if then) block.
800 void add_S(RegisterID rd
, RegisterID rn
, ARMThumbImmediate imm
)
802 // Rd can only be SP if Rn is also SP.
803 ASSERT((rd
!= ARMRegisters::sp
) || (rn
== ARMRegisters::sp
));
804 ASSERT(rd
!= ARMRegisters::pc
);
805 ASSERT(rn
!= ARMRegisters::pc
);
806 ASSERT(imm
.isEncodedImm());
808 if (!((rd
| rn
) & 8)) {
810 m_formatter
.oneWordOp7Reg3Reg3Reg3(OP_ADD_imm_T1
, (RegisterID
)imm
.getUInt3(), rn
, rd
);
812 } else if ((rd
== rn
) && imm
.isUInt8()) {
813 m_formatter
.oneWordOp5Reg3Imm8(OP_ADD_imm_T2
, rd
, imm
.getUInt8());
818 m_formatter
.twoWordOp5i6Imm4Reg4EncodedImm(OP_ADD_S_imm_T3
, rn
, rd
, imm
);
821 // Not allowed in an IT (if then) block?
822 void add_S(RegisterID rd
, RegisterID rn
, RegisterID rm
, ShiftTypeAndAmount shift
)
824 ASSERT((rd
!= ARMRegisters::sp
) || (rn
== ARMRegisters::sp
));
825 ASSERT(rd
!= ARMRegisters::pc
);
826 ASSERT(rn
!= ARMRegisters::pc
);
828 m_formatter
.twoWordOp12Reg4FourFours(OP_ADD_S_reg_T3
, rn
, FourFours(shift
.hi4(), rd
, shift
.lo4(), rm
));
831 // Not allowed in an IT (if then) block.
832 void add_S(RegisterID rd
, RegisterID rn
, RegisterID rm
)
834 if (!((rd
| rn
| rm
) & 8))
835 m_formatter
.oneWordOp7Reg3Reg3Reg3(OP_ADD_reg_T1
, rm
, rn
, rd
);
837 add_S(rd
, rn
, rm
, ShiftTypeAndAmount());
840 void ARM_and(RegisterID rd
, RegisterID rn
, ARMThumbImmediate imm
)
844 ASSERT(imm
.isEncodedImm());
845 m_formatter
.twoWordOp5i6Imm4Reg4EncodedImm(OP_AND_imm_T1
, rn
, rd
, imm
);
848 void ARM_and(RegisterID rd
, RegisterID rn
, RegisterID rm
, ShiftTypeAndAmount shift
)
853 m_formatter
.twoWordOp12Reg4FourFours(OP_AND_reg_T2
, rn
, FourFours(shift
.hi4(), rd
, shift
.lo4(), rm
));
856 void ARM_and(RegisterID rd
, RegisterID rn
, RegisterID rm
)
858 if ((rd
== rn
) && !((rd
| rm
) & 8))
859 m_formatter
.oneWordOp10Reg3Reg3(OP_AND_reg_T1
, rm
, rd
);
860 else if ((rd
== rm
) && !((rd
| rn
) & 8))
861 m_formatter
.oneWordOp10Reg3Reg3(OP_AND_reg_T1
, rn
, rd
);
863 ARM_and(rd
, rn
, rm
, ShiftTypeAndAmount());
866 void asr(RegisterID rd
, RegisterID rm
, int32_t shiftAmount
)
870 ShiftTypeAndAmount
shift(SRType_ASR
, shiftAmount
);
871 m_formatter
.twoWordOp16FourFours(OP_ASR_imm_T1
, FourFours(shift
.hi4(), rd
, shift
.lo4(), rm
));
874 void asr(RegisterID rd
, RegisterID rn
, RegisterID rm
)
879 m_formatter
.twoWordOp12Reg4FourFours(OP_ASR_reg_T2
, rn
, FourFours(0xf, rd
, 0, rm
));
882 // Only allowed in IT (if then) block if last instruction.
885 m_formatter
.twoWordOp16Op16(OP_B_T4a
, OP_B_T4b
);
886 return JmpSrc(m_formatter
.size());
889 // Only allowed in IT (if then) block if last instruction.
890 JmpSrc
blx(RegisterID rm
)
892 ASSERT(rm
!= ARMRegisters::pc
);
893 m_formatter
.oneWordOp8RegReg143(OP_BLX
, rm
, (RegisterID
)8);
894 return JmpSrc(m_formatter
.size());
897 // Only allowed in IT (if then) block if last instruction.
898 JmpSrc
bx(RegisterID rm
)
900 m_formatter
.oneWordOp8RegReg143(OP_BX
, rm
, (RegisterID
)0);
901 return JmpSrc(m_formatter
.size());
904 void bkpt(uint8_t imm
=0)
906 m_formatter
.oneWordOp8Imm8(OP_BKPT
, imm
);
909 void cmn(RegisterID rn
, ARMThumbImmediate imm
)
911 ASSERT(rn
!= ARMRegisters::pc
);
912 ASSERT(imm
.isEncodedImm());
914 m_formatter
.twoWordOp5i6Imm4Reg4EncodedImm(OP_CMN_imm
, rn
, (RegisterID
)0xf, imm
);
917 void cmp(RegisterID rn
, ARMThumbImmediate imm
)
919 ASSERT(rn
!= ARMRegisters::pc
);
920 ASSERT(imm
.isEncodedImm());
922 if (!(rn
& 8) && imm
.isUInt8())
923 m_formatter
.oneWordOp5Reg3Imm8(OP_CMP_imm_T1
, rn
, imm
.getUInt8());
925 m_formatter
.twoWordOp5i6Imm4Reg4EncodedImm(OP_CMP_imm_T2
, rn
, (RegisterID
)0xf, imm
);
928 void cmp(RegisterID rn
, RegisterID rm
, ShiftTypeAndAmount shift
)
930 ASSERT(rn
!= ARMRegisters::pc
);
932 m_formatter
.twoWordOp12Reg4FourFours(OP_CMP_reg_T2
, rn
, FourFours(shift
.hi4(), 0xf, shift
.lo4(), rm
));
935 void cmp(RegisterID rn
, RegisterID rm
)
938 cmp(rn
, rm
, ShiftTypeAndAmount());
940 m_formatter
.oneWordOp10Reg3Reg3(OP_CMP_reg_T1
, rm
, rn
);
943 // xor is not spelled with an 'e'. :-(
944 void eor(RegisterID rd
, RegisterID rn
, ARMThumbImmediate imm
)
948 ASSERT(imm
.isEncodedImm());
949 m_formatter
.twoWordOp5i6Imm4Reg4EncodedImm(OP_EOR_imm_T1
, rn
, rd
, imm
);
952 // xor is not spelled with an 'e'. :-(
953 void eor(RegisterID rd
, RegisterID rn
, RegisterID rm
, ShiftTypeAndAmount shift
)
958 m_formatter
.twoWordOp12Reg4FourFours(OP_EOR_reg_T2
, rn
, FourFours(shift
.hi4(), rd
, shift
.lo4(), rm
));
961 // xor is not spelled with an 'e'. :-(
962 void eor(RegisterID rd
, RegisterID rn
, RegisterID rm
)
964 if ((rd
== rn
) && !((rd
| rm
) & 8))
965 m_formatter
.oneWordOp10Reg3Reg3(OP_EOR_reg_T1
, rm
, rd
);
966 else if ((rd
== rm
) && !((rd
| rn
) & 8))
967 m_formatter
.oneWordOp10Reg3Reg3(OP_EOR_reg_T1
, rn
, rd
);
969 eor(rd
, rn
, rm
, ShiftTypeAndAmount());
972 void it(Condition cond
)
974 m_formatter
.oneWordOp8Imm8(OP_IT
, ifThenElse(cond
));
977 void it(Condition cond
, bool inst2if
)
979 m_formatter
.oneWordOp8Imm8(OP_IT
, ifThenElse(cond
, inst2if
));
982 void it(Condition cond
, bool inst2if
, bool inst3if
)
984 m_formatter
.oneWordOp8Imm8(OP_IT
, ifThenElse(cond
, inst2if
, inst3if
));
987 void it(Condition cond
, bool inst2if
, bool inst3if
, bool inst4if
)
989 m_formatter
.oneWordOp8Imm8(OP_IT
, ifThenElse(cond
, inst2if
, inst3if
, inst4if
));
992 // rt == ARMRegisters::pc only allowed if last instruction in IT (if then) block.
993 void ldr(RegisterID rt
, RegisterID rn
, ARMThumbImmediate imm
)
995 ASSERT(rn
!= ARMRegisters::pc
); // LDR (literal)
996 ASSERT(imm
.isUInt12());
998 if (!((rt
| rn
) & 8) && imm
.isUInt7())
999 m_formatter
.oneWordOp5Imm5Reg3Reg3(OP_LDR_imm_T1
, imm
.getUInt7() >> 2, rn
, rt
);
1000 else if ((rn
== ARMRegisters::sp
) && !(rt
& 8) && imm
.isUInt10())
1001 m_formatter
.oneWordOp5Reg3Imm8(OP_LDR_imm_T2
, rt
, imm
.getUInt10() >> 2);
1003 m_formatter
.twoWordOp12Reg4Reg4Imm12(OP_LDR_imm_T3
, rn
, rt
, imm
.getUInt12());
1006 // If index is set, this is a regular offset or a pre-indexed load;
1007 // if index is not set then is is a post-index load.
1009 // If wback is set rn is updated - this is a pre or post index load,
1010 // if wback is not set this is a regular offset memory access.
1012 // (-255 <= offset <= 255)
1014 // _tmp = _reg + offset
1015 // MEM[index ? _tmp : _reg] = REG[rt]
1016 // if (wback) REG[rn] = _tmp
1017 void ldr(RegisterID rt
, RegisterID rn
, int offset
, bool index
, bool wback
)
1019 ASSERT(rt
!= ARMRegisters::pc
);
1020 ASSERT(rn
!= ARMRegisters::pc
);
1021 ASSERT(index
|| wback
);
1022 ASSERT(!wback
| (rt
!= rn
));
1029 ASSERT((offset
& ~0xff) == 0);
1031 offset
|= (wback
<< 8);
1032 offset
|= (add
<< 9);
1033 offset
|= (index
<< 10);
1034 offset
|= (1 << 11);
1036 m_formatter
.twoWordOp12Reg4Reg4Imm12(OP_LDR_imm_T4
, rn
, rt
, offset
);
1039 // rt == ARMRegisters::pc only allowed if last instruction in IT (if then) block.
1040 void ldr(RegisterID rt
, RegisterID rn
, RegisterID rm
, unsigned shift
=0)
1042 ASSERT(rn
!= ARMRegisters::pc
); // LDR (literal)
1043 ASSERT(!BadReg(rm
));
1046 if (!shift
&& !((rt
| rn
| rm
) & 8))
1047 m_formatter
.oneWordOp7Reg3Reg3Reg3(OP_LDR_reg_T1
, rm
, rn
, rt
);
1049 m_formatter
.twoWordOp12Reg4FourFours(OP_LDR_reg_T2
, rn
, FourFours(rt
, 0, shift
, rm
));
1052 // rt == ARMRegisters::pc only allowed if last instruction in IT (if then) block.
1053 void ldrh(RegisterID rt
, RegisterID rn
, ARMThumbImmediate imm
)
1055 ASSERT(rn
!= ARMRegisters::pc
); // LDR (literal)
1056 ASSERT(imm
.isUInt12());
1058 if (!((rt
| rn
) & 8) && imm
.isUInt6())
1059 m_formatter
.oneWordOp5Imm5Reg3Reg3(OP_LDRH_imm_T1
, imm
.getUInt6() >> 2, rn
, rt
);
1061 m_formatter
.twoWordOp12Reg4Reg4Imm12(OP_LDRH_imm_T2
, rn
, rt
, imm
.getUInt12());
1064 // If index is set, this is a regular offset or a pre-indexed load;
1065 // if index is not set then is is a post-index load.
1067 // If wback is set rn is updated - this is a pre or post index load,
1068 // if wback is not set this is a regular offset memory access.
1070 // (-255 <= offset <= 255)
1072 // _tmp = _reg + offset
1073 // MEM[index ? _tmp : _reg] = REG[rt]
1074 // if (wback) REG[rn] = _tmp
1075 void ldrh(RegisterID rt
, RegisterID rn
, int offset
, bool index
, bool wback
)
1077 ASSERT(rt
!= ARMRegisters::pc
);
1078 ASSERT(rn
!= ARMRegisters::pc
);
1079 ASSERT(index
|| wback
);
1080 ASSERT(!wback
| (rt
!= rn
));
1087 ASSERT((offset
& ~0xff) == 0);
1089 offset
|= (wback
<< 8);
1090 offset
|= (add
<< 9);
1091 offset
|= (index
<< 10);
1092 offset
|= (1 << 11);
1094 m_formatter
.twoWordOp12Reg4Reg4Imm12(OP_LDRH_imm_T3
, rn
, rt
, offset
);
1097 void ldrh(RegisterID rt
, RegisterID rn
, RegisterID rm
, unsigned shift
=0)
1099 ASSERT(!BadReg(rt
)); // Memory hint
1100 ASSERT(rn
!= ARMRegisters::pc
); // LDRH (literal)
1101 ASSERT(!BadReg(rm
));
1104 if (!shift
&& !((rt
| rn
| rm
) & 8))
1105 m_formatter
.oneWordOp7Reg3Reg3Reg3(OP_LDRH_reg_T1
, rm
, rn
, rt
);
1107 m_formatter
.twoWordOp12Reg4FourFours(OP_LDRH_reg_T2
, rn
, FourFours(rt
, 0, shift
, rm
));
1110 void ldrb(RegisterID rt
, RegisterID rn
, ARMThumbImmediate imm
)
1112 ASSERT(rn
!= ARMRegisters::pc
); // LDR (literal)
1113 ASSERT(imm
.isUInt12());
1115 if (!((rt
| rn
) & 8) && imm
.isUInt5())
1116 m_formatter
.oneWordOp5Imm5Reg3Reg3(OP_LDRB_imm_T1
, imm
.getUInt5(), rn
, rt
);
1118 m_formatter
.twoWordOp12Reg4Reg4Imm12(OP_LDRB_imm_T2
, rn
, rt
, imm
.getUInt12());
1121 void ldrb(RegisterID rt
, RegisterID rn
, int offset
, bool index
, bool wback
)
1123 ASSERT(rt
!= ARMRegisters::pc
);
1124 ASSERT(rn
!= ARMRegisters::pc
);
1125 ASSERT(index
|| wback
);
1126 ASSERT(!wback
| (rt
!= rn
));
1134 ASSERT(!(offset
& ~0xff));
1136 offset
|= (wback
<< 8);
1137 offset
|= (add
<< 9);
1138 offset
|= (index
<< 10);
1139 offset
|= (1 << 11);
1141 m_formatter
.twoWordOp12Reg4Reg4Imm12(OP_LDRB_imm_T3
, rn
, rt
, offset
);
1144 void ldrb(RegisterID rt
, RegisterID rn
, RegisterID rm
, unsigned shift
= 0)
1146 ASSERT(rn
!= ARMRegisters::pc
); // LDR (literal)
1147 ASSERT(!BadReg(rm
));
1150 if (!shift
&& !((rt
| rn
| rm
) & 8))
1151 m_formatter
.oneWordOp7Reg3Reg3Reg3(OP_LDRB_reg_T1
, rm
, rn
, rt
);
1153 m_formatter
.twoWordOp12Reg4FourFours(OP_LDRB_reg_T2
, rn
, FourFours(rt
, 0, shift
, rm
));
1156 void lsl(RegisterID rd
, RegisterID rm
, int32_t shiftAmount
)
1158 ASSERT(!BadReg(rd
));
1159 ASSERT(!BadReg(rm
));
1160 ShiftTypeAndAmount
shift(SRType_LSL
, shiftAmount
);
1161 m_formatter
.twoWordOp16FourFours(OP_LSL_imm_T1
, FourFours(shift
.hi4(), rd
, shift
.lo4(), rm
));
1164 void lsl(RegisterID rd
, RegisterID rn
, RegisterID rm
)
1166 ASSERT(!BadReg(rd
));
1167 ASSERT(!BadReg(rn
));
1168 ASSERT(!BadReg(rm
));
1169 m_formatter
.twoWordOp12Reg4FourFours(OP_LSL_reg_T2
, rn
, FourFours(0xf, rd
, 0, rm
));
1172 void lsr(RegisterID rd
, RegisterID rm
, int32_t shiftAmount
)
1174 ASSERT(!BadReg(rd
));
1175 ASSERT(!BadReg(rm
));
1176 ShiftTypeAndAmount
shift(SRType_LSR
, shiftAmount
);
1177 m_formatter
.twoWordOp16FourFours(OP_LSR_imm_T1
, FourFours(shift
.hi4(), rd
, shift
.lo4(), rm
));
1180 void lsr(RegisterID rd
, RegisterID rn
, RegisterID rm
)
1182 ASSERT(!BadReg(rd
));
1183 ASSERT(!BadReg(rn
));
1184 ASSERT(!BadReg(rm
));
1185 m_formatter
.twoWordOp12Reg4FourFours(OP_LSR_reg_T2
, rn
, FourFours(0xf, rd
, 0, rm
));
1188 void movT3(RegisterID rd
, ARMThumbImmediate imm
)
1190 ASSERT(imm
.isValid());
1191 ASSERT(!imm
.isEncodedImm());
1192 ASSERT(!BadReg(rd
));
1194 m_formatter
.twoWordOp5i6Imm4Reg4EncodedImm(OP_MOV_imm_T3
, imm
.m_value
.imm4
, rd
, imm
);
1197 void mov(RegisterID rd
, ARMThumbImmediate imm
)
1199 ASSERT(imm
.isValid());
1200 ASSERT(!BadReg(rd
));
1202 if ((rd
< 8) && imm
.isUInt8())
1203 m_formatter
.oneWordOp5Reg3Imm8(OP_MOV_imm_T1
, rd
, imm
.getUInt8());
1204 else if (imm
.isEncodedImm())
1205 m_formatter
.twoWordOp5i6Imm4Reg4EncodedImm(OP_MOV_imm_T2
, 0xf, rd
, imm
);
1210 void mov(RegisterID rd
, RegisterID rm
)
1212 m_formatter
.oneWordOp8RegReg143(OP_MOV_reg_T1
, rm
, rd
);
1215 void movt(RegisterID rd
, ARMThumbImmediate imm
)
1217 ASSERT(imm
.isUInt16());
1218 ASSERT(!BadReg(rd
));
1219 m_formatter
.twoWordOp5i6Imm4Reg4EncodedImm(OP_MOVT
, imm
.m_value
.imm4
, rd
, imm
);
1222 void mvn(RegisterID rd
, ARMThumbImmediate imm
)
1224 ASSERT(imm
.isEncodedImm());
1225 ASSERT(!BadReg(rd
));
1227 m_formatter
.twoWordOp5i6Imm4Reg4EncodedImm(OP_MVN_imm
, 0xf, rd
, imm
);
1230 void mvn(RegisterID rd
, RegisterID rm
, ShiftTypeAndAmount shift
)
1232 ASSERT(!BadReg(rd
));
1233 ASSERT(!BadReg(rm
));
1234 m_formatter
.twoWordOp16FourFours(OP_MVN_reg_T2
, FourFours(shift
.hi4(), rd
, shift
.lo4(), rm
));
1237 void mvn(RegisterID rd
, RegisterID rm
)
1239 if (!((rd
| rm
) & 8))
1240 m_formatter
.oneWordOp10Reg3Reg3(OP_MVN_reg_T1
, rm
, rd
);
1242 mvn(rd
, rm
, ShiftTypeAndAmount());
1245 void neg(RegisterID rd
, RegisterID rm
)
1247 ARMThumbImmediate zero
= ARMThumbImmediate::makeUInt12(0);
1251 void orr(RegisterID rd
, RegisterID rn
, ARMThumbImmediate imm
)
1253 ASSERT(!BadReg(rd
));
1254 ASSERT(!BadReg(rn
));
1255 ASSERT(imm
.isEncodedImm());
1256 m_formatter
.twoWordOp5i6Imm4Reg4EncodedImm(OP_ORR_imm_T1
, rn
, rd
, imm
);
1259 void orr(RegisterID rd
, RegisterID rn
, RegisterID rm
, ShiftTypeAndAmount shift
)
1261 ASSERT(!BadReg(rd
));
1262 ASSERT(!BadReg(rn
));
1263 ASSERT(!BadReg(rm
));
1264 m_formatter
.twoWordOp12Reg4FourFours(OP_ORR_reg_T2
, rn
, FourFours(shift
.hi4(), rd
, shift
.lo4(), rm
));
1267 void orr(RegisterID rd
, RegisterID rn
, RegisterID rm
)
1269 if ((rd
== rn
) && !((rd
| rm
) & 8))
1270 m_formatter
.oneWordOp10Reg3Reg3(OP_ORR_reg_T1
, rm
, rd
);
1271 else if ((rd
== rm
) && !((rd
| rn
) & 8))
1272 m_formatter
.oneWordOp10Reg3Reg3(OP_ORR_reg_T1
, rn
, rd
);
1274 orr(rd
, rn
, rm
, ShiftTypeAndAmount());
1277 void orr_S(RegisterID rd
, RegisterID rn
, RegisterID rm
, ShiftTypeAndAmount shift
)
1279 ASSERT(!BadReg(rd
));
1280 ASSERT(!BadReg(rn
));
1281 ASSERT(!BadReg(rm
));
1282 m_formatter
.twoWordOp12Reg4FourFours(OP_ORR_S_reg_T2
, rn
, FourFours(shift
.hi4(), rd
, shift
.lo4(), rm
));
1285 void orr_S(RegisterID rd
, RegisterID rn
, RegisterID rm
)
1287 if ((rd
== rn
) && !((rd
| rm
) & 8))
1288 m_formatter
.oneWordOp10Reg3Reg3(OP_ORR_reg_T1
, rm
, rd
);
1289 else if ((rd
== rm
) && !((rd
| rn
) & 8))
1290 m_formatter
.oneWordOp10Reg3Reg3(OP_ORR_reg_T1
, rn
, rd
);
1292 orr_S(rd
, rn
, rm
, ShiftTypeAndAmount());
1295 void ror(RegisterID rd
, RegisterID rm
, int32_t shiftAmount
)
1297 ASSERT(!BadReg(rd
));
1298 ASSERT(!BadReg(rm
));
1299 ShiftTypeAndAmount
shift(SRType_ROR
, shiftAmount
);
1300 m_formatter
.twoWordOp16FourFours(OP_ROR_imm_T1
, FourFours(shift
.hi4(), rd
, shift
.lo4(), rm
));
1303 void ror(RegisterID rd
, RegisterID rn
, RegisterID rm
)
1305 ASSERT(!BadReg(rd
));
1306 ASSERT(!BadReg(rn
));
1307 ASSERT(!BadReg(rm
));
1308 m_formatter
.twoWordOp12Reg4FourFours(OP_ROR_reg_T2
, rn
, FourFours(0xf, rd
, 0, rm
));
1311 void smull(RegisterID rdLo
, RegisterID rdHi
, RegisterID rn
, RegisterID rm
)
1313 ASSERT(!BadReg(rdLo
));
1314 ASSERT(!BadReg(rdHi
));
1315 ASSERT(!BadReg(rn
));
1316 ASSERT(!BadReg(rm
));
1317 ASSERT(rdLo
!= rdHi
);
1318 m_formatter
.twoWordOp12Reg4FourFours(OP_SMULL_T1
, rn
, FourFours(rdLo
, rdHi
, 0, rm
));
1321 // rt == ARMRegisters::pc only allowed if last instruction in IT (if then) block.
1322 void str(RegisterID rt
, RegisterID rn
, ARMThumbImmediate imm
)
1324 ASSERT(rt
!= ARMRegisters::pc
);
1325 ASSERT(rn
!= ARMRegisters::pc
);
1326 ASSERT(imm
.isUInt12());
1328 if (!((rt
| rn
) & 8) && imm
.isUInt7())
1329 m_formatter
.oneWordOp5Imm5Reg3Reg3(OP_STR_imm_T1
, imm
.getUInt7() >> 2, rn
, rt
);
1330 else if ((rn
== ARMRegisters::sp
) && !(rt
& 8) && imm
.isUInt10())
1331 m_formatter
.oneWordOp5Reg3Imm8(OP_STR_imm_T2
, rt
, imm
.getUInt10() >> 2);
1333 m_formatter
.twoWordOp12Reg4Reg4Imm12(OP_STR_imm_T3
, rn
, rt
, imm
.getUInt12());
1336 // If index is set, this is a regular offset or a pre-indexed store;
1337 // if index is not set then is is a post-index store.
1339 // If wback is set rn is updated - this is a pre or post index store,
1340 // if wback is not set this is a regular offset memory access.
1342 // (-255 <= offset <= 255)
1344 // _tmp = _reg + offset
1345 // MEM[index ? _tmp : _reg] = REG[rt]
1346 // if (wback) REG[rn] = _tmp
1347 void str(RegisterID rt
, RegisterID rn
, int offset
, bool index
, bool wback
)
1349 ASSERT(rt
!= ARMRegisters::pc
);
1350 ASSERT(rn
!= ARMRegisters::pc
);
1351 ASSERT(index
|| wback
);
1352 ASSERT(!wback
| (rt
!= rn
));
1359 ASSERT((offset
& ~0xff) == 0);
1361 offset
|= (wback
<< 8);
1362 offset
|= (add
<< 9);
1363 offset
|= (index
<< 10);
1364 offset
|= (1 << 11);
1366 m_formatter
.twoWordOp12Reg4Reg4Imm12(OP_STR_imm_T4
, rn
, rt
, offset
);
1369 // rt == ARMRegisters::pc only allowed if last instruction in IT (if then) block.
1370 void str(RegisterID rt
, RegisterID rn
, RegisterID rm
, unsigned shift
=0)
1372 ASSERT(rn
!= ARMRegisters::pc
);
1373 ASSERT(!BadReg(rm
));
1376 if (!shift
&& !((rt
| rn
| rm
) & 8))
1377 m_formatter
.oneWordOp7Reg3Reg3Reg3(OP_STR_reg_T1
, rm
, rn
, rt
);
1379 m_formatter
.twoWordOp12Reg4FourFours(OP_STR_reg_T2
, rn
, FourFours(rt
, 0, shift
, rm
));
1382 void sub(RegisterID rd
, RegisterID rn
, ARMThumbImmediate imm
)
1384 // Rd can only be SP if Rn is also SP.
1385 ASSERT((rd
!= ARMRegisters::sp
) || (rn
== ARMRegisters::sp
));
1386 ASSERT(rd
!= ARMRegisters::pc
);
1387 ASSERT(rn
!= ARMRegisters::pc
);
1388 ASSERT(imm
.isValid());
1390 if ((rn
== ARMRegisters::sp
) && (rd
== ARMRegisters::sp
) && imm
.isUInt9()) {
1391 m_formatter
.oneWordOp9Imm7(OP_SUB_SP_imm_T1
, imm
.getUInt9() >> 2);
1393 } else if (!((rd
| rn
) & 8)) {
1394 if (imm
.isUInt3()) {
1395 m_formatter
.oneWordOp7Reg3Reg3Reg3(OP_SUB_imm_T1
, (RegisterID
)imm
.getUInt3(), rn
, rd
);
1397 } else if ((rd
== rn
) && imm
.isUInt8()) {
1398 m_formatter
.oneWordOp5Reg3Imm8(OP_SUB_imm_T2
, rd
, imm
.getUInt8());
1403 if (imm
.isEncodedImm())
1404 m_formatter
.twoWordOp5i6Imm4Reg4EncodedImm(OP_SUB_imm_T3
, rn
, rd
, imm
);
1406 ASSERT(imm
.isUInt12());
1407 m_formatter
.twoWordOp5i6Imm4Reg4EncodedImm(OP_SUB_imm_T4
, rn
, rd
, imm
);
1411 void sub(RegisterID rd
, ARMThumbImmediate imm
, RegisterID rn
)
1413 ASSERT(rd
!= ARMRegisters::pc
);
1414 ASSERT(rn
!= ARMRegisters::pc
);
1415 ASSERT(imm
.isValid());
1416 ASSERT(imm
.isUInt12());
1418 if (!((rd
| rn
) & 8) && !imm
.getUInt12())
1419 m_formatter
.oneWordOp10Reg3Reg3(OP_RSB_imm_T1
, rn
, rd
);
1421 m_formatter
.twoWordOp5i6Imm4Reg4EncodedImm(OP_RSB_imm_T2
, rn
, rd
, imm
);
1424 void sub(RegisterID rd
, RegisterID rn
, RegisterID rm
, ShiftTypeAndAmount shift
)
1426 ASSERT((rd
!= ARMRegisters::sp
) || (rn
== ARMRegisters::sp
));
1427 ASSERT(rd
!= ARMRegisters::pc
);
1428 ASSERT(rn
!= ARMRegisters::pc
);
1429 ASSERT(!BadReg(rm
));
1430 m_formatter
.twoWordOp12Reg4FourFours(OP_SUB_reg_T2
, rn
, FourFours(shift
.hi4(), rd
, shift
.lo4(), rm
));
1433 // NOTE: In an IT block, add doesn't modify the flags register.
1434 void sub(RegisterID rd
, RegisterID rn
, RegisterID rm
)
1436 if (!((rd
| rn
| rm
) & 8))
1437 m_formatter
.oneWordOp7Reg3Reg3Reg3(OP_SUB_reg_T1
, rm
, rn
, rd
);
1439 sub(rd
, rn
, rm
, ShiftTypeAndAmount());
1442 // Not allowed in an IT (if then) block.
1443 void sub_S(RegisterID rd
, RegisterID rn
, ARMThumbImmediate imm
)
1445 // Rd can only be SP if Rn is also SP.
1446 ASSERT((rd
!= ARMRegisters::sp
) || (rn
== ARMRegisters::sp
));
1447 ASSERT(rd
!= ARMRegisters::pc
);
1448 ASSERT(rn
!= ARMRegisters::pc
);
1449 ASSERT(imm
.isValid());
1451 if ((rn
== ARMRegisters::sp
) && (rd
== ARMRegisters::sp
) && imm
.isUInt9()) {
1452 m_formatter
.oneWordOp9Imm7(OP_SUB_SP_imm_T1
, imm
.getUInt9() >> 2);
1454 } else if (!((rd
| rn
) & 8)) {
1455 if (imm
.isUInt3()) {
1456 m_formatter
.oneWordOp7Reg3Reg3Reg3(OP_SUB_imm_T1
, (RegisterID
)imm
.getUInt3(), rn
, rd
);
1458 } else if ((rd
== rn
) && imm
.isUInt8()) {
1459 m_formatter
.oneWordOp5Reg3Imm8(OP_SUB_imm_T2
, rd
, imm
.getUInt8());
1464 m_formatter
.twoWordOp5i6Imm4Reg4EncodedImm(OP_SUB_S_imm_T3
, rn
, rd
, imm
);
1467 // Not allowed in an IT (if then) block?
1468 void sub_S(RegisterID rd
, RegisterID rn
, RegisterID rm
, ShiftTypeAndAmount shift
)
1470 ASSERT((rd
!= ARMRegisters::sp
) || (rn
== ARMRegisters::sp
));
1471 ASSERT(rd
!= ARMRegisters::pc
);
1472 ASSERT(rn
!= ARMRegisters::pc
);
1473 ASSERT(!BadReg(rm
));
1474 m_formatter
.twoWordOp12Reg4FourFours(OP_SUB_S_reg_T2
, rn
, FourFours(shift
.hi4(), rd
, shift
.lo4(), rm
));
1477 // Not allowed in an IT (if then) block.
1478 void sub_S(RegisterID rd
, RegisterID rn
, RegisterID rm
)
1480 if (!((rd
| rn
| rm
) & 8))
1481 m_formatter
.oneWordOp7Reg3Reg3Reg3(OP_SUB_reg_T1
, rm
, rn
, rd
);
1483 sub_S(rd
, rn
, rm
, ShiftTypeAndAmount());
1486 void tst(RegisterID rn
, ARMThumbImmediate imm
)
1488 ASSERT(!BadReg(rn
));
1489 ASSERT(imm
.isEncodedImm());
1491 m_formatter
.twoWordOp5i6Imm4Reg4EncodedImm(OP_TST_imm
, rn
, (RegisterID
)0xf, imm
);
1494 void tst(RegisterID rn
, RegisterID rm
, ShiftTypeAndAmount shift
)
1496 ASSERT(!BadReg(rn
));
1497 ASSERT(!BadReg(rm
));
1498 m_formatter
.twoWordOp12Reg4FourFours(OP_TST_reg_T2
, rn
, FourFours(shift
.hi4(), 0xf, shift
.lo4(), rm
));
1501 void tst(RegisterID rn
, RegisterID rm
)
1504 tst(rn
, rm
, ShiftTypeAndAmount());
1506 m_formatter
.oneWordOp10Reg3Reg3(OP_TST_reg_T1
, rm
, rn
);
1509 void vadd_F64(FPDoubleRegisterID rd
, FPDoubleRegisterID rn
, FPDoubleRegisterID rm
)
1511 m_formatter
.vfpOp(OP_VADD_T2
, OP_VADD_T2b
, true, rn
, rd
, rm
);
1514 void vcmp_F64(FPDoubleRegisterID rd
, FPDoubleRegisterID rm
)
1516 m_formatter
.vfpOp(OP_VCMP_T1
, OP_VCMP_T1b
, true, VFPOperand(4), rd
, rm
);
1519 void vcvt_F64_S32(FPDoubleRegisterID rd
, FPSingleRegisterID rm
)
1521 // boolean values are 64bit (toInt, unsigned, roundZero)
1522 m_formatter
.vfpOp(OP_VCVT_FPIVFP
, OP_VCVT_FPIVFPb
, true, vcvtOp(false, false, false), rd
, rm
);
1525 void vcvtr_S32_F64(FPSingleRegisterID rd
, FPDoubleRegisterID rm
)
1527 // boolean values are 64bit (toInt, unsigned, roundZero)
1528 m_formatter
.vfpOp(OP_VCVT_FPIVFP
, OP_VCVT_FPIVFPb
, true, vcvtOp(true, false, true), rd
, rm
);
1531 void vdiv_F64(FPDoubleRegisterID rd
, FPDoubleRegisterID rn
, FPDoubleRegisterID rm
)
1533 m_formatter
.vfpOp(OP_VDIV
, OP_VDIVb
, true, rn
, rd
, rm
);
1536 void vldr(FPDoubleRegisterID rd
, RegisterID rn
, int32_t imm
)
1538 m_formatter
.vfpMemOp(OP_VLDR
, OP_VLDRb
, true, rn
, rd
, imm
);
1541 void vmov_F64_0(FPDoubleRegisterID rd
)
1543 m_formatter
.vfpOp(OP_VMOV_IMM_T2
, OP_VMOV_IMM_T2b
, true, VFPOperand(0), rd
, VFPOperand(0));
1546 void vmov(RegisterID rd
, FPSingleRegisterID rn
)
1548 ASSERT(!BadReg(rd
));
1549 m_formatter
.vfpOp(OP_VMOV_CtoS
, OP_VMOV_CtoSb
, false, rn
, rd
, VFPOperand(0));
1552 void vmov(FPSingleRegisterID rd
, RegisterID rn
)
1554 ASSERT(!BadReg(rn
));
1555 m_formatter
.vfpOp(OP_VMOV_StoC
, OP_VMOV_StoCb
, false, rd
, rn
, VFPOperand(0));
1558 void vmrs(RegisterID reg
= ARMRegisters::pc
)
1560 ASSERT(reg
!= ARMRegisters::sp
);
1561 m_formatter
.vfpOp(OP_VMRS
, OP_VMRSb
, false, VFPOperand(1), VFPOperand(0x10 | reg
), VFPOperand(0));
1564 void vmul_F64(FPDoubleRegisterID rd
, FPDoubleRegisterID rn
, FPDoubleRegisterID rm
)
1566 m_formatter
.vfpOp(OP_VMUL_T2
, OP_VMUL_T2b
, true, rn
, rd
, rm
);
1569 void vstr(FPDoubleRegisterID rd
, RegisterID rn
, int32_t imm
)
1571 m_formatter
.vfpMemOp(OP_VSTR
, OP_VSTRb
, true, rn
, rd
, imm
);
1574 void vsub_F64(FPDoubleRegisterID rd
, FPDoubleRegisterID rn
, FPDoubleRegisterID rm
)
1576 m_formatter
.vfpOp(OP_VSUB_T2
, OP_VSUB_T2b
, true, rn
, rd
, rm
);
1581 return JmpDst(m_formatter
.size());
1584 JmpDst
align(int alignment
)
1586 while (!m_formatter
.isAligned(alignment
))
1592 static void* getRelocatedAddress(void* code
, JmpSrc jump
)
1594 ASSERT(jump
.m_offset
!= -1);
1596 return reinterpret_cast<void*>(reinterpret_cast<ptrdiff_t>(code
) + jump
.m_offset
);
1599 static void* getRelocatedAddress(void* code
, JmpDst destination
)
1601 ASSERT(destination
.m_offset
!= -1);
1603 return reinterpret_cast<void*>(reinterpret_cast<ptrdiff_t>(code
) + destination
.m_offset
);
1606 static int getDifferenceBetweenLabels(JmpDst src
, JmpDst dst
)
1608 return dst
.m_offset
- src
.m_offset
;
1611 static int getDifferenceBetweenLabels(JmpDst src
, JmpSrc dst
)
1613 return dst
.m_offset
- src
.m_offset
;
1616 static int getDifferenceBetweenLabels(JmpSrc src
, JmpDst dst
)
1618 return dst
.m_offset
- src
.m_offset
;
1621 // Assembler admin methods:
1625 return m_formatter
.size();
1628 void* executableCopy(ExecutablePool
* allocator
)
1630 void* copy
= m_formatter
.executableCopy(allocator
);
1632 unsigned jumpCount
= m_jumpsToLink
.size();
1633 for (unsigned i
= 0; i
< jumpCount
; ++i
) {
1634 uint16_t* location
= reinterpret_cast<uint16_t*>(reinterpret_cast<intptr_t>(copy
) + m_jumpsToLink
[i
].from
);
1635 uint16_t* target
= reinterpret_cast<uint16_t*>(reinterpret_cast<intptr_t>(copy
) + m_jumpsToLink
[i
].to
);
1636 linkJumpAbsolute(location
, target
);
1638 m_jumpsToLink
.clear();
1644 static unsigned getCallReturnOffset(JmpSrc call
)
1646 ASSERT(call
.m_offset
>= 0);
1647 return call
.m_offset
;
1650 // Linking & patching:
1652 // 'link' and 'patch' methods are for use on unprotected code - such as the code
1653 // within the AssemblerBuffer, and code being patched by the patch buffer. Once
1654 // code has been finalized it is (platform support permitting) within a non-
1655 // writable region of memory; to modify the code in an execute-only execuable
1656 // pool the 'repatch' and 'relink' methods should be used.
1658 void linkJump(JmpSrc from
, JmpDst to
)
1660 ASSERT(to
.m_offset
!= -1);
1661 ASSERT(from
.m_offset
!= -1);
1662 m_jumpsToLink
.append(LinkRecord(from
.m_offset
, to
.m_offset
));
1665 static void linkJump(void* code
, JmpSrc from
, void* to
)
1667 ASSERT(from
.m_offset
!= -1);
1669 uint16_t* location
= reinterpret_cast<uint16_t*>(reinterpret_cast<intptr_t>(code
) + from
.m_offset
);
1670 linkJumpAbsolute(location
, to
);
1673 // bah, this mathod should really be static, since it is used by the LinkBuffer.
1674 // return a bool saying whether the link was successful?
1675 static void linkCall(void* code
, JmpSrc from
, void* to
)
1677 ASSERT(!(reinterpret_cast<intptr_t>(code
) & 1));
1678 ASSERT(from
.m_offset
!= -1);
1679 ASSERT(reinterpret_cast<intptr_t>(to
) & 1);
1681 setPointer(reinterpret_cast<uint16_t*>(reinterpret_cast<intptr_t>(code
) + from
.m_offset
) - 1, to
);
1684 static void linkPointer(void* code
, JmpDst where
, void* value
)
1686 setPointer(reinterpret_cast<char*>(code
) + where
.m_offset
, value
);
1689 static void relinkJump(void* from
, void* to
)
1691 ASSERT(!(reinterpret_cast<intptr_t>(from
) & 1));
1692 ASSERT(!(reinterpret_cast<intptr_t>(to
) & 1));
1694 linkJumpAbsolute(reinterpret_cast<uint16_t*>(from
), to
);
1696 ExecutableAllocator::cacheFlush(reinterpret_cast<uint16_t*>(from
) - 5, 5 * sizeof(uint16_t));
1699 static void relinkCall(void* from
, void* to
)
1701 ASSERT(!(reinterpret_cast<intptr_t>(from
) & 1));
1702 ASSERT(reinterpret_cast<intptr_t>(to
) & 1);
1704 setPointer(reinterpret_cast<uint16_t*>(from
) - 1, to
);
1706 ExecutableAllocator::cacheFlush(reinterpret_cast<uint16_t*>(from
) - 5, 4 * sizeof(uint16_t));
1709 static void repatchInt32(void* where
, int32_t value
)
1711 ASSERT(!(reinterpret_cast<intptr_t>(where
) & 1));
1713 setInt32(where
, value
);
1715 ExecutableAllocator::cacheFlush(reinterpret_cast<uint16_t*>(where
) - 4, 4 * sizeof(uint16_t));
1718 static void repatchPointer(void* where
, void* value
)
1720 ASSERT(!(reinterpret_cast<intptr_t>(where
) & 1));
1722 setPointer(where
, value
);
1724 ExecutableAllocator::cacheFlush(reinterpret_cast<uint16_t*>(where
) - 4, 4 * sizeof(uint16_t));
1727 static void repatchLoadPtrToLEA(void* where
)
1729 ASSERT(!(reinterpret_cast<intptr_t>(where
) & 1));
1730 uint16_t* loadOp
= reinterpret_cast<uint16_t*>(where
) + 4;
1732 ASSERT((loadOp
[0] & 0xfff0) == OP_LDR_reg_T2
);
1733 ASSERT((loadOp
[1] & 0x0ff0) == 0);
1734 int rn
= loadOp
[0] & 0xf;
1735 int rt
= loadOp
[1] >> 12;
1736 int rm
= loadOp
[1] & 0xf;
1738 loadOp
[0] = OP_ADD_reg_T3
| rn
;
1739 loadOp
[1] = rt
<< 8 | rm
;
1740 ExecutableAllocator::cacheFlush(loadOp
, sizeof(uint32_t));
1744 // VFP operations commonly take one or more 5-bit operands, typically representing a
1745 // floating point register number. This will commonly be encoded in the instruction
1746 // in two parts, with one single bit field, and one 4-bit field. In the case of
1747 // double precision operands the high bit of the register number will be encoded
1748 // separately, and for single precision operands the high bit of the register number
1749 // will be encoded individually.
1750 // VFPOperand encapsulates a 5-bit VFP operand, with bits 0..3 containing the 4-bit
1751 // field to be encoded together in the instruction (the low 4-bits of a double
1752 // register number, or the high 4-bits of a single register number), and bit 4
1753 // contains the bit value to be encoded individually.
1755 explicit VFPOperand(uint32_t value
)
1758 ASSERT(!(m_value
& ~0x1f));
1761 VFPOperand(FPDoubleRegisterID reg
)
1766 VFPOperand(RegisterID reg
)
1771 VFPOperand(FPSingleRegisterID reg
)
1772 : m_value(((reg
& 1) << 4) | (reg
>> 1)) // rotate the lowest bit of 'reg' to the top.
1778 return m_value
>> 4;
1783 return m_value
& 0xf;
1789 VFPOperand
vcvtOp(bool toInteger
, bool isUnsigned
, bool isRoundZero
)
1791 // Cannot specify rounding when converting to float.
1792 ASSERT(toInteger
|| !isRoundZero
);
1796 // opc2 indicates both toInteger & isUnsigned.
1797 op
|= isUnsigned
? 0x4 : 0x5;
1798 // 'op' field in instruction is isRoundZero
1802 // 'op' field in instruction is isUnsigned
1806 return VFPOperand(op
);
1809 static void setInt32(void* code
, uint32_t value
)
1811 uint16_t* location
= reinterpret_cast<uint16_t*>(code
);
1812 ASSERT(isMOV_imm_T3(location
- 4) && isMOVT(location
- 2));
1814 ARMThumbImmediate lo16
= ARMThumbImmediate::makeUInt16(static_cast<uint16_t>(value
));
1815 ARMThumbImmediate hi16
= ARMThumbImmediate::makeUInt16(static_cast<uint16_t>(value
>> 16));
1816 location
[-4] = twoWordOp5i6Imm4Reg4EncodedImmFirst(OP_MOV_imm_T3
, lo16
);
1817 location
[-3] = twoWordOp5i6Imm4Reg4EncodedImmSecond((location
[-3] >> 8) & 0xf, lo16
);
1818 location
[-2] = twoWordOp5i6Imm4Reg4EncodedImmFirst(OP_MOVT
, hi16
);
1819 location
[-1] = twoWordOp5i6Imm4Reg4EncodedImmSecond((location
[-1] >> 8) & 0xf, hi16
);
1821 ExecutableAllocator::cacheFlush(location
- 4, 4 * sizeof(uint16_t));
1824 static void setPointer(void* code
, void* value
)
1826 setInt32(code
, reinterpret_cast<uint32_t>(value
));
1829 static bool isB(void* address
)
1831 uint16_t* instruction
= static_cast<uint16_t*>(address
);
1832 return ((instruction
[0] & 0xf800) == OP_B_T4a
) && ((instruction
[1] & 0xd000) == OP_B_T4b
);
1835 static bool isBX(void* address
)
1837 uint16_t* instruction
= static_cast<uint16_t*>(address
);
1838 return (instruction
[0] & 0xff87) == OP_BX
;
1841 static bool isMOV_imm_T3(void* address
)
1843 uint16_t* instruction
= static_cast<uint16_t*>(address
);
1844 return ((instruction
[0] & 0xFBF0) == OP_MOV_imm_T3
) && ((instruction
[1] & 0x8000) == 0);
1847 static bool isMOVT(void* address
)
1849 uint16_t* instruction
= static_cast<uint16_t*>(address
);
1850 return ((instruction
[0] & 0xFBF0) == OP_MOVT
) && ((instruction
[1] & 0x8000) == 0);
1853 static bool isNOP_T1(void* address
)
1855 uint16_t* instruction
= static_cast<uint16_t*>(address
);
1856 return instruction
[0] == OP_NOP_T1
;
1859 static bool isNOP_T2(void* address
)
1861 uint16_t* instruction
= static_cast<uint16_t*>(address
);
1862 return (instruction
[0] == OP_NOP_T2a
) && (instruction
[1] == OP_NOP_T2b
);
1865 static void linkJumpAbsolute(uint16_t* instruction
, void* target
)
1867 // FIMXE: this should be up in the MacroAssembler layer. :-(
1868 const uint16_t JUMP_TEMPORARY_REGISTER
= ARMRegisters::ip
;
1870 ASSERT(!(reinterpret_cast<intptr_t>(instruction
) & 1));
1871 ASSERT(!(reinterpret_cast<intptr_t>(target
) & 1));
1873 ASSERT( (isMOV_imm_T3(instruction
- 5) && isMOVT(instruction
- 3) && isBX(instruction
- 1))
1874 || (isNOP_T1(instruction
- 5) && isNOP_T2(instruction
- 4) && isB(instruction
- 2)) );
1876 intptr_t relative
= reinterpret_cast<intptr_t>(target
) - (reinterpret_cast<intptr_t>(instruction
));
1878 // From Cortex-A8 errata:
1879 // If the 32-bit Thumb-2 branch instruction spans two 4KiB regions and
1880 // the target of the branch falls within the first region it is
1881 // possible for the processor to incorrectly determine the branch
1882 // instruction, and it is also possible in some cases for the processor
1883 // to enter a deadlock state.
1884 // The instruction is spanning two pages if it ends at an address ending 0x002
1885 bool spansTwo4K
= ((reinterpret_cast<intptr_t>(instruction
) & 0xfff) == 0x002);
1886 // The target is in the first page if the jump branch back by [3..0x1002] bytes
1887 bool targetInFirstPage
= (relative
>= -0x1002) && (relative
< -2);
1888 bool wouldTriggerA8Errata
= spansTwo4K
&& targetInFirstPage
;
1890 if (((relative
<< 7) >> 7) == relative
&& !wouldTriggerA8Errata
) {
1891 // ARM encoding for the top two bits below the sign bit is 'peculiar'.
1893 relative
^= 0xC00000;
1895 // All branch offsets should be an even distance.
1896 ASSERT(!(relative
& 1));
1897 // There may be a better way to fix this, but right now put the NOPs first, since in the
1898 // case of an conditional branch this will be coming after an ITTT predicating *three*
1899 // instructions! Looking backwards to modify the ITTT to an IT is not easy, due to
1900 // variable wdith encoding - the previous instruction might *look* like an ITTT but
1901 // actually be the second half of a 2-word op.
1902 instruction
[-5] = OP_NOP_T1
;
1903 instruction
[-4] = OP_NOP_T2a
;
1904 instruction
[-3] = OP_NOP_T2b
;
1905 instruction
[-2] = OP_B_T4a
| ((relative
& 0x1000000) >> 14) | ((relative
& 0x3ff000) >> 12);
1906 instruction
[-1] = OP_B_T4b
| ((relative
& 0x800000) >> 10) | ((relative
& 0x400000) >> 11) | ((relative
& 0xffe) >> 1);
1908 ARMThumbImmediate lo16
= ARMThumbImmediate::makeUInt16(static_cast<uint16_t>(reinterpret_cast<uint32_t>(target
) + 1));
1909 ARMThumbImmediate hi16
= ARMThumbImmediate::makeUInt16(static_cast<uint16_t>(reinterpret_cast<uint32_t>(target
) >> 16));
1910 instruction
[-5] = twoWordOp5i6Imm4Reg4EncodedImmFirst(OP_MOV_imm_T3
, lo16
);
1911 instruction
[-4] = twoWordOp5i6Imm4Reg4EncodedImmSecond(JUMP_TEMPORARY_REGISTER
, lo16
);
1912 instruction
[-3] = twoWordOp5i6Imm4Reg4EncodedImmFirst(OP_MOVT
, hi16
);
1913 instruction
[-2] = twoWordOp5i6Imm4Reg4EncodedImmSecond(JUMP_TEMPORARY_REGISTER
, hi16
);
1914 instruction
[-1] = OP_BX
| (JUMP_TEMPORARY_REGISTER
<< 3);
1918 static uint16_t twoWordOp5i6Imm4Reg4EncodedImmFirst(uint16_t op
, ARMThumbImmediate imm
)
1920 return op
| (imm
.m_value
.i
<< 10) | imm
.m_value
.imm4
;
1922 static uint16_t twoWordOp5i6Imm4Reg4EncodedImmSecond(uint16_t rd
, ARMThumbImmediate imm
)
1924 return (imm
.m_value
.imm3
<< 12) | (rd
<< 8) | imm
.m_value
.imm8
;
1927 class ARMInstructionFormatter
{
1929 void oneWordOp5Reg3Imm8(OpcodeID op
, RegisterID rd
, uint8_t imm
)
1931 m_buffer
.putShort(op
| (rd
<< 8) | imm
);
1934 void oneWordOp5Imm5Reg3Reg3(OpcodeID op
, uint8_t imm
, RegisterID reg1
, RegisterID reg2
)
1936 m_buffer
.putShort(op
| (imm
<< 6) | (reg1
<< 3) | reg2
);
1939 void oneWordOp7Reg3Reg3Reg3(OpcodeID op
, RegisterID reg1
, RegisterID reg2
, RegisterID reg3
)
1941 m_buffer
.putShort(op
| (reg1
<< 6) | (reg2
<< 3) | reg3
);
1944 void oneWordOp8Imm8(OpcodeID op
, uint8_t imm
)
1946 m_buffer
.putShort(op
| imm
);
1949 void oneWordOp8RegReg143(OpcodeID op
, RegisterID reg1
, RegisterID reg2
)
1951 m_buffer
.putShort(op
| ((reg2
& 8) << 4) | (reg1
<< 3) | (reg2
& 7));
1953 void oneWordOp9Imm7(OpcodeID op
, uint8_t imm
)
1955 m_buffer
.putShort(op
| imm
);
1958 void oneWordOp10Reg3Reg3(OpcodeID op
, RegisterID reg1
, RegisterID reg2
)
1960 m_buffer
.putShort(op
| (reg1
<< 3) | reg2
);
1963 void twoWordOp12Reg4FourFours(OpcodeID1 op
, RegisterID reg
, FourFours ff
)
1965 m_buffer
.putShort(op
| reg
);
1966 m_buffer
.putShort(ff
.m_u
.value
);
1969 void twoWordOp16FourFours(OpcodeID1 op
, FourFours ff
)
1971 m_buffer
.putShort(op
);
1972 m_buffer
.putShort(ff
.m_u
.value
);
1975 void twoWordOp16Op16(OpcodeID1 op1
, OpcodeID2 op2
)
1977 m_buffer
.putShort(op1
);
1978 m_buffer
.putShort(op2
);
1981 void twoWordOp5i6Imm4Reg4EncodedImm(OpcodeID1 op
, int imm4
, RegisterID rd
, ARMThumbImmediate imm
)
1983 ARMThumbImmediate newImm
= imm
;
1984 newImm
.m_value
.imm4
= imm4
;
1986 m_buffer
.putShort(ARMv7Assembler::twoWordOp5i6Imm4Reg4EncodedImmFirst(op
, newImm
));
1987 m_buffer
.putShort(ARMv7Assembler::twoWordOp5i6Imm4Reg4EncodedImmSecond(rd
, newImm
));
1990 void twoWordOp12Reg4Reg4Imm12(OpcodeID1 op
, RegisterID reg1
, RegisterID reg2
, uint16_t imm
)
1992 m_buffer
.putShort(op
| reg1
);
1993 m_buffer
.putShort((reg2
<< 12) | imm
);
1996 // Formats up instructions of the pattern:
1997 // 111111111B11aaaa:bbbb222SA2C2cccc
1998 // Where 1s in the pattern come from op1, 2s in the pattern come from op2, S is the provided size bit.
1999 // Operands provide 5 bit values of the form Aaaaa, Bbbbb, Ccccc.
2000 void vfpOp(OpcodeID1 op1
, OpcodeID2 op2
, bool size
, VFPOperand a
, VFPOperand b
, VFPOperand c
)
2002 ASSERT(!(op1
& 0x004f));
2003 ASSERT(!(op2
& 0xf1af));
2004 m_buffer
.putShort(op1
| b
.bits1() << 6 | a
.bits4());
2005 m_buffer
.putShort(op2
| b
.bits4() << 12 | size
<< 8 | a
.bits1() << 7 | c
.bits1() << 5 | c
.bits4());
2008 // Arm vfp addresses can be offset by a 9-bit ones-comp immediate, left shifted by 2.
2009 // (i.e. +/-(0..255) 32-bit words)
2010 void vfpMemOp(OpcodeID1 op1
, OpcodeID2 op2
, bool size
, RegisterID rn
, VFPOperand rd
, int32_t imm
)
2018 uint32_t offset
= imm
;
2019 ASSERT(!(offset
& ~0x3fc));
2022 m_buffer
.putShort(op1
| (up
<< 7) | rd
.bits1() << 6 | rn
);
2023 m_buffer
.putShort(op2
| rd
.bits4() << 12 | size
<< 8 | offset
);
2026 // Administrative methods:
2028 size_t size() const { return m_buffer
.size(); }
2029 bool isAligned(int alignment
) const { return m_buffer
.isAligned(alignment
); }
2030 void* data() const { return m_buffer
.data(); }
2031 void* executableCopy(ExecutablePool
* allocator
) { return m_buffer
.executableCopy(allocator
); }
2034 AssemblerBuffer m_buffer
;
2037 Vector
<LinkRecord
> m_jumpsToLink
;
2042 #endif // ENABLE(ASSEMBLER) && CPU(ARM_THUMB2)
2044 #endif // ARMAssembler_h