llvm.org GIT mirror llvm / d12fce1
Mips ELF: MicroMips direct object Little endian support. Test included. Patch by Zoran Jovanovich git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188024 91177308-0d34-0410-b5e6-96231b3b80d8 Jack Carter 6 years ago
4 changed file(s) with 126 addition(s) and 52 deletion(s). Raw diff Collapse all Expand all
3838 MCContext &Ctx;
3939 const MCSubtargetInfo &STI;
4040 bool IsLittleEndian;
41 bool IsMicroMips;
4142
4243 public:
4344 MipsMCCodeEmitter(const MCInstrInfo &mcii, MCContext &Ctx_,
4445 const MCSubtargetInfo &sti, bool IsLittle) :
45 MCII(mcii), Ctx(Ctx_), STI (sti), IsLittleEndian(IsLittle) {}
46 MCII(mcii), Ctx(Ctx_), STI (sti), IsLittleEndian(IsLittle) {
47 IsMicroMips = STI.getFeatureBits() & Mips::FeatureMicroMips;
48 }
4649
4750 ~MipsMCCodeEmitter() {}
4851
5255
5356 void EmitInstruction(uint64_t Val, unsigned Size, raw_ostream &OS) const {
5457 // Output the instruction encoding in little endian byte order.
55 for (unsigned i = 0; i < Size; ++i) {
56 unsigned Shift = IsLittleEndian ? i * 8 : (Size - 1 - i) * 8;
57 EmitByte((Val >> Shift) & 0xff, OS);
58 // Little-endian byte ordering:
59 // mips32r2: 4 | 3 | 2 | 1
60 // microMIPS: 2 | 1 | 4 | 3
61 if (IsLittleEndian && Size == 4 && IsMicroMips) {
62 EmitInstruction(Val>>16, 2, OS);
63 EmitInstruction(Val, 2, OS);
64 } else {
65 for (unsigned i = 0; i < Size; ++i) {
66 unsigned Shift = IsLittleEndian ? i * 8 : (Size - 1 - i) * 8;
67 EmitByte((Val >> Shift) & 0xff, OS);
68 }
5869 }
5970 }
6071
None # RUN: llvm-mc %s -triple=mipsel -show-encoding -mattr=micromips | FileCheck %s
0 # RUN: llvm-mc %s -triple=mipsel -show-encoding -mattr=micromips | FileCheck -check-prefix=CHECK-EL %s
1 # RUN: llvm-mc %s -triple=mips -show-encoding -mattr=micromips | FileCheck -check-prefix=CHECK-EB %s
12 # Check that the assembler can handle the documented syntax
23 # for arithmetic and logical instructions.
34 #------------------------------------------------------------------------------
45 # Arithmetic and Logical Instructions
56 #------------------------------------------------------------------------------
6 # CHECK: add $9, $6, $7 # encoding: [0x10,0x49,0xe6,0x00]
7 # CHECK: addi $9, $6, 17767 # encoding: [0x67,0x45,0x26,0x11]
8 # CHECK: addiu $9, $6, -15001 # encoding: [0x67,0xc5,0x26,0x31]
9 # CHECK: addi $9, $6, 17767 # encoding: [0x67,0x45,0x26,0x11]
10 # CHECK: addiu $9, $6, -15001 # encoding: [0x67,0xc5,0x26,0x31]
11 # CHECK: addu $9, $6, $7 # encoding: [0x50,0x49,0xe6,0x00]
12 # CHECK: sub $9, $6, $7 # encoding: [0x90,0x49,0xe6,0x00]
13 # CHECK: subu $4, $3, $5 # encoding: [0xd0,0x21,0xa3,0x00]
14 # CHECK: neg $6, $7 # encoding: [0x90,0x31,0xe0,0x00]
15 # CHECK: negu $6, $7 # encoding: [0xd0,0x31,0xe0,0x00]
16 # CHECK: move $7, $8 # encoding: [0x50,0x39,0x08,0x00]
17 # CHECK: slt $3, $3, $5 # encoding: [0x50,0x1b,0xa3,0x00]
18 # CHECK: slti $3, $3, 103 # encoding: [0x67,0x00,0x63,0x90]
19 # CHECK: slti $3, $3, 103 # encoding: [0x67,0x00,0x63,0x90]
20 # CHECK: sltiu $3, $3, 103 # encoding: [0x67,0x00,0x63,0xb0]
21 # CHECK: sltu $3, $3, $5 # encoding: [0x90,0x1b,0xa3,0x00]
22 # CHECK: and $9, $6, $7 # encoding: [0x50,0x4a,0xe6,0x00]
23 # CHECK: andi $9, $6, 17767 # encoding: [0x67,0x45,0x26,0xd1]
24 # CHECK: andi $9, $6, 17767 # encoding: [0x67,0x45,0x26,0xd1]
25 # CHECK: or $3, $4, $5 # encoding: [0x90,0x1a,0xa4,0x00]
26 # CHECK: ori $9, $6, 17767 # encoding: [0x67,0x45,0x26,0x51]
27 # CHECK: xor $3, $3, $5 # encoding: [0x10,0x1b,0xa3,0x00]
28 # CHECK: xori $9, $6, 17767 # encoding: [0x67,0x45,0x26,0x71]
29 # CHECK: xori $9, $6, 17767 # encoding: [0x67,0x45,0x26,0x71]
30 # CHECK: nor $9, $6, $7 # encoding: [0xd0,0x4a,0xe6,0x00]
31 # CHECK: not $7, $8 # encoding: [0xd0,0x3a,0x08,0x00]
32 # CHECK: mul $9, $6, $7 # encoding: [0x10,0x4a,0xe6,0x00]
33 # CHECK: mult $9, $7 # encoding: [0x3c,0x8b,0xe9,0x00]
34 # CHECK: multu $9, $7 # encoding: [0x3c,0x9b,0xe9,0x00]
7 # Little endian
8 #------------------------------------------------------------------------------
9 # CHECK-EL: add $9, $6, $7 # encoding: [0xe6,0x00,0x10,0x49]
10 # CHECK-EL: addi $9, $6, 17767 # encoding: [0x26,0x11,0x67,0x45]
11 # CHECK-EL: addiu $9, $6, -15001 # encoding: [0x26,0x31,0x67,0xc5]
12 # CHECK-EL: addi $9, $6, 17767 # encoding: [0x26,0x11,0x67,0x45]
13 # CHECK-EL: addiu $9, $6, -15001 # encoding: [0x26,0x31,0x67,0xc5]
14 # CHECK-EL: addu $9, $6, $7 # encoding: [0xe6,0x00,0x50,0x49]
15 # CHECK-EL: sub $9, $6, $7 # encoding: [0xe6,0x00,0x90,0x49]
16 # CHECK-EL: subu $4, $3, $5 # encoding: [0xa3,0x00,0xd0,0x21]
17 # CHECK-EL: neg $6, $7 # encoding: [0xe0,0x00,0x90,0x31]
18 # CHECK-EL: negu $6, $7 # encoding: [0xe0,0x00,0xd0,0x31]
19 # CHECK-EL: move $7, $8 # encoding: [0x08,0x00,0x50,0x39]
20 # CHECK-EL: slt $3, $3, $5 # encoding: [0xa3,0x00,0x50,0x1b]
21 # CHECK-EL: slti $3, $3, 103 # encoding: [0x63,0x90,0x67,0x00]
22 # CHECK-EL: slti $3, $3, 103 # encoding: [0x63,0x90,0x67,0x00]
23 # CHECK-EL: sltiu $3, $3, 103 # encoding: [0x63,0xb0,0x67,0x00]
24 # CHECK-EL: sltu $3, $3, $5 # encoding: [0xa3,0x00,0x90,0x1b]
25 # CHECK-EL: and $9, $6, $7 # encoding: [0xe6,0x00,0x50,0x4a]
26 # CHECK-EL: andi $9, $6, 17767 # encoding: [0x26,0xd1,0x67,0x45]
27 # CHECK-EL: andi $9, $6, 17767 # encoding: [0x26,0xd1,0x67,0x45]
28 # CHECK-EL: or $3, $4, $5 # encoding: [0xa4,0x00,0x90,0x1a]
29 # CHECK-EL: ori $9, $6, 17767 # encoding: [0x26,0x51,0x67,0x45]
30 # CHECK-EL: xor $3, $3, $5 # encoding: [0xa3,0x00,0x10,0x1b]
31 # CHECK-EL: xori $9, $6, 17767 # encoding: [0x26,0x71,0x67,0x45]
32 # CHECK-EL: xori $9, $6, 17767 # encoding: [0x26,0x71,0x67,0x45]
33 # CHECK-EL: nor $9, $6, $7 # encoding: [0xe6,0x00,0xd0,0x4a]
34 # CHECK-EL: not $7, $8 # encoding: [0x08,0x00,0xd0,0x3a]
35 # CHECK-EL: mul $9, $6, $7 # encoding: [0xe6,0x00,0x10,0x4a]
36 # CHECK-EL: mult $9, $7 # encoding: [0xe9,0x00,0x3c,0x8b]
37 # CHECK-EL: multu $9, $7 # encoding: [0xe9,0x00,0x3c,0x9b]
38 #------------------------------------------------------------------------------
39 # Big endian
40 #------------------------------------------------------------------------------
41 # CHECK-EB: add $9, $6, $7 # encoding: [0x00,0xe6,0x49,0x10]
42 # CHECK-EB: addi $9, $6, 17767 # encoding: [0x11,0x26,0x45,0x67]
43 # CHECK-EB: addiu $9, $6, -15001 # encoding: [0x31,0x26,0xc5,0x67]
44 # CHECK-EB: addi $9, $6, 17767 # encoding: [0x11,0x26,0x45,0x67]
45 # CHECK-EB: addiu $9, $6, -15001 # encoding: [0x31,0x26,0xc5,0x67]
46 # CHECK-EB: addu $9, $6, $7 # encoding: [0x00,0xe6,0x49,0x50]
47 # CHECK-EB: sub $9, $6, $7 # encoding: [0x00,0xe6,0x49,0x90]
48 # CHECK-EB: subu $4, $3, $5 # encoding: [0x00,0xa3,0x21,0xd0]
49 # CHECK-EB: neg $6, $7 # encoding: [0x00,0xe0,0x31,0x90]
50 # CHECK-EB: negu $6, $7 # encoding: [0x00,0xe0,0x31,0xd0]
51 # CHECK-EB: move $7, $8 # encoding: [0x00,0x08,0x39,0x50]
52 # CHECK-EB: slt $3, $3, $5 # encoding: [0x00,0xa3,0x1b,0x50]
53 # CHECK-EB: slti $3, $3, 103 # encoding: [0x90,0x63,0x00,0x67]
54 # CHECK-EB: slti $3, $3, 103 # encoding: [0x90,0x63,0x00,0x67]
55 # CHECK-EB: sltiu $3, $3, 103 # encoding: [0xb0,0x63,0x00,0x67]
56 # CHECK-EB: sltu $3, $3, $5 # encoding: [0x00,0xa3,0x1b,0x90]
57 # CHECK-EB: and $9, $6, $7 # encoding: [0x00,0xe6,0x4a,0x50]
58 # CHECK-EB: andi $9, $6, 17767 # encoding: [0xd1,0x26,0x45,0x67]
59 # CHECK-EB: andi $9, $6, 17767 # encoding: [0xd1,0x26,0x45,0x67]
60 # CHECK-EB: or $3, $4, $5 # encoding: [0x00,0xa4,0x1a,0x90]
61 # CHECK-EB: ori $9, $6, 17767 # encoding: [0x51,0x26,0x45,0x67]
62 # CHECK-EB: xor $3, $3, $5 # encoding: [0x00,0xa3,0x1b,0x10]
63 # CHECK-EB: xori $9, $6, 17767 # encoding: [0x71,0x26,0x45,0x67]
64 # CHECK-EB: xori $9, $6, 17767 # encoding: [0x71,0x26,0x45,0x67]
65 # CHECK-EB: nor $9, $6, $7 # encoding: [0x00,0xe6,0x4a,0xd0]
66 # CHECK-EB: not $7, $8 # encoding: [0x00,0x08,0x3a,0xd0]
67 # CHECK-EB: mul $9, $6, $7 # encoding: [0x00,0xe6,0x4a,0x10]
68 # CHECK-EB: mult $9, $7 # encoding: [0x00,0xe9,0x8b,0x3c]
69 # CHECK-EB: multu $9, $7 # encoding: [0x00,0xe9,0x9b,0x3c]
3570 add $9, $6, $7
3671 add $9, $6, 17767
3772 addu $9, $6, -15001
None # RUN: llvm-mc %s -triple=mipsel -show-encoding -mattr=micromips | FileCheck %s
0 # RUN: llvm-mc %s -triple=mipsel -show-encoding -mattr=micromips | FileCheck -check-prefix=CHECK-EL %s
1 # RUN: llvm-mc %s -triple=mips -show-encoding -mattr=micromips | FileCheck -check-prefix=CHECK-EB %s
12 # Check that the assembler can handle the documented syntax
23 # for load and store instructions.
34 #------------------------------------------------------------------------------
45 # Load and Store Instructions
56 #------------------------------------------------------------------------------
6 # CHECK: lb $5, 8($4) # encoding: [0x08,0x00,0xa4,0x1c]
7 # CHECK: lbu $6, 8($4) # encoding: [0x08,0x00,0xc4,0x14]
8 # CHECK: lh $2, 8($4) # encoding: [0x08,0x00,0x44,0x3c]
9 # CHECK: lhu $4, 8($2) # encoding: [0x08,0x00,0x82,0x34]
10 # CHECK: lw $6, 4($5) # encoding: [0x04,0x00,0xc5,0xfc]
11 # CHECK: sb $5, 8($4) # encoding: [0x08,0x00,0xa4,0x18]
12 # CHECK: sh $2, 8($4) # encoding: [0x08,0x00,0x44,0x38]
13 # CHECK: sw $5, 4($6) # encoding: [0x04,0x00,0xa6,0xf8]
7 # Little endian
8 #------------------------------------------------------------------------------
9 # CHECK-EL: lb $5, 8($4) # encoding: [0xa4,0x1c,0x08,0x00]
10 # CHECK-EL: lbu $6, 8($4) # encoding: [0xc4,0x14,0x08,0x00]
11 # CHECK-EL: lh $2, 8($4) # encoding: [0x44,0x3c,0x08,0x00]
12 # CHECK-EL: lhu $4, 8($2) # encoding: [0x82,0x34,0x08,0x00]
13 # CHECK-EL: lw $6, 4($5) # encoding: [0xc5,0xfc,0x04,0x00]
14 # CHECK-EL: sb $5, 8($4) # encoding: [0xa4,0x18,0x08,0x00]
15 # CHECK-EL: sh $2, 8($4) # encoding: [0x44,0x38,0x08,0x00]
16 # CHECK-EL: sw $5, 4($6) # encoding: [0xa6,0xf8,0x04,0x00]
17 #------------------------------------------------------------------------------
18 # Big endian
19 #------------------------------------------------------------------------------
20 # CHECK-EB: lb $5, 8($4) # encoding: [0x1c,0xa4,0x00,0x08]
21 # CHECK-EB: lbu $6, 8($4) # encoding: [0x14,0xc4,0x00,0x08]
22 # CHECK-EB: lh $2, 8($4) # encoding: [0x3c,0x44,0x00,0x08]
23 # CHECK-EB: lhu $4, 8($2) # encoding: [0x34,0x82,0x00,0x08]
24 # CHECK-EB: lw $6, 4($5) # encoding: [0xfc,0xc5,0x00,0x04]
25 # CHECK-EB: sb $5, 8($4) # encoding: [0x18,0xa4,0x00,0x08]
26 # CHECK-EB: sh $2, 8($4) # encoding: [0x38,0x44,0x00,0x08]
27 # CHECK-EB: sw $5, 4($6) # encoding: [0xf8,0xa6,0x00,0x04]
1428 lb $5, 8($4)
1529 lbu $6, 8($4)
1630 lh $2, 8($4)
None # RUN: llvm-mc %s -triple=mipsel -show-encoding -mcpu=mips32r2 -mattr=micromips | FileCheck %s
0 # RUN: llvm-mc %s -triple=mipsel -show-encoding -mcpu=mips32r2 -mattr=micromips | FileCheck -check-prefix=CHECK-EL %s
1 # RUN: llvm-mc %s -triple=mips -show-encoding -mcpu=mips32r2 -mattr=micromips | FileCheck -check-prefix=CHECK-EB %s
12 # Check that the assembler can handle the documented syntax
23 # for shift instructions.
34 #------------------------------------------------------------------------------
45 # Shift Instructions
56 #------------------------------------------------------------------------------
6 # CHECK: sll $4, $3, 7 # encoding: [0x00,0x38,0x83,0x00]
7 # CHECK: sllv $2, $3, $5 # encoding: [0x10,0x10,0x65,0x00]
8 # CHECK: sra $4, $3, 7 # encoding: [0x80,0x38,0x83,0x00]
9 # CHECK: srav $2, $3, $5 # encoding: [0x90,0x10,0x65,0x00]
10 # CHECK: srl $4, $3, 7 # encoding: [0x40,0x38,0x83,0x00]
11 # CHECK: srlv $2, $3, $5 # encoding: [0x50,0x10,0x65,0x00]
12 # CHECK: rotr $9, $6, 7 # encoding: [0xc0,0x38,0x26,0x01]
13 # CHECK: rotrv $9, $6, $7 # encoding: [0xd0,0x48,0xc7,0x00]
7 # Little endian
8 #------------------------------------------------------------------------------
9 # CHECK-EL: sll $4, $3, 7 # encoding: [0x83,0x00,0x00,0x38]
10 # CHECK-EL: sllv $2, $3, $5 # encoding: [0x65,0x00,0x10,0x10]
11 # CHECK-EL: sra $4, $3, 7 # encoding: [0x83,0x00,0x80,0x38]
12 # CHECK-EL: srav $2, $3, $5 # encoding: [0x65,0x00,0x90,0x10]
13 # CHECK-EL: srl $4, $3, 7 # encoding: [0x83,0x00,0x40,0x38]
14 # CHECK-EL: srlv $2, $3, $5 # encoding: [0x65,0x00,0x50,0x10]
15 # CHECK-EL: rotr $9, $6, 7 # encoding: [0x26,0x01,0xc0,0x38]
16 # CHECK-EL: rotrv $9, $6, $7 # encoding: [0xc7,0x00,0xd0,0x48]
17 #------------------------------------------------------------------------------
18 # Big endian
19 #------------------------------------------------------------------------------
20 # CHECK-EB: sll $4, $3, 7 # encoding: [0x00,0x83,0x38,0x00]
21 # CHECK-EB: sllv $2, $3, $5 # encoding: [0x00,0x65,0x10,0x10]
22 # CHECK-EB: sra $4, $3, 7 # encoding: [0x00,0x83,0x38,0x80]
23 # CHECK-EB: srav $2, $3, $5 # encoding: [0x00,0x65,0x10,0x90]
24 # CHECK-EB: srl $4, $3, 7 # encoding: [0x00,0x83,0x38,0x40]
25 # CHECK-EB: srlv $2, $3, $5 # encoding: [0x00,0x65,0x10,0x50]
26 # CHECK-EB: rotr $9, $6, 7 # encoding: [0x01,0x26,0x38,0xc0]
27 # CHECK-EB: rotrv $9, $6, $7 # encoding: [0x00,0xc7,0x48,0xd0]
1428 sll $4, $3, 7
1529 sllv $2, $3, $5
1630 sra $4, $3, 7