Skip to content

Commit aa2b927

Browse files
author
Jozef Kolek
committed
[mips][microMIPS] Implement disassembler support for 16-bit instructions LI16, ADDIUR1SP, ADDIUR2 and ADDIUS5
Differential Revision: http://reviews.llvm.org/D6419 llvm-svn: 222887
1 parent 13404da commit aa2b927

File tree

4 files changed

+105
-3
lines changed

4 files changed

+105
-3
lines changed

llvm/lib/Target/Mips/Disassembler/MipsDisassembler.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,26 @@ static DecodeStatus DecodeSpecial3LlSc(MCInst &Inst,
287287
uint64_t Address,
288288
const void *Decoder);
289289

290+
static DecodeStatus DecodeAddiur2Simm7(MCInst &Inst,
291+
unsigned Value,
292+
uint64_t Address,
293+
const void *Decoder);
294+
295+
static DecodeStatus DecodeUImm6Lsl2(MCInst &Inst,
296+
unsigned Value,
297+
uint64_t Address,
298+
const void *Decoder);
299+
300+
static DecodeStatus DecodeLiSimm7(MCInst &Inst,
301+
unsigned Value,
302+
uint64_t Address,
303+
const void *Decoder);
304+
305+
static DecodeStatus DecodeSimm4(MCInst &Inst,
306+
unsigned Value,
307+
uint64_t Address,
308+
const void *Decoder);
309+
290310
static DecodeStatus DecodeSimm16(MCInst &Inst,
291311
unsigned Insn,
292312
uint64_t Address,
@@ -1458,6 +1478,46 @@ static DecodeStatus DecodeJumpTargetMM(MCInst &Inst,
14581478
return MCDisassembler::Success;
14591479
}
14601480

1481+
static DecodeStatus DecodeAddiur2Simm7(MCInst &Inst,
1482+
unsigned Value,
1483+
uint64_t Address,
1484+
const void *Decoder) {
1485+
if (Value == 0)
1486+
Inst.addOperand(MCOperand::CreateImm(1));
1487+
else if (Value == 0x7)
1488+
Inst.addOperand(MCOperand::CreateImm(-1));
1489+
else
1490+
Inst.addOperand(MCOperand::CreateImm(Value << 2));
1491+
return MCDisassembler::Success;
1492+
}
1493+
1494+
static DecodeStatus DecodeUImm6Lsl2(MCInst &Inst,
1495+
unsigned Value,
1496+
uint64_t Address,
1497+
const void *Decoder) {
1498+
Inst.addOperand(MCOperand::CreateImm(Value << 2));
1499+
return MCDisassembler::Success;
1500+
}
1501+
1502+
static DecodeStatus DecodeLiSimm7(MCInst &Inst,
1503+
unsigned Value,
1504+
uint64_t Address,
1505+
const void *Decoder) {
1506+
if (Value == 0x7F)
1507+
Inst.addOperand(MCOperand::CreateImm(-1));
1508+
else
1509+
Inst.addOperand(MCOperand::CreateImm(Value));
1510+
return MCDisassembler::Success;
1511+
}
1512+
1513+
static DecodeStatus DecodeSimm4(MCInst &Inst,
1514+
unsigned Value,
1515+
uint64_t Address,
1516+
const void *Decoder) {
1517+
Inst.addOperand(MCOperand::CreateImm(SignExtend32<4>(Value)));
1518+
return MCDisassembler::Success;
1519+
}
1520+
14611521
static DecodeStatus DecodeSimm16(MCInst &Inst,
14621522
unsigned Insn,
14631523
uint64_t Address,

llvm/lib/Target/Mips/MicroMipsInstrInfo.td

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
def addrimm12 : ComplexPattern<iPTR, 2, "selectIntAddrMM", [frameindex]>;
22

3-
def simm4 : Operand<i32>;
4-
def simm7 : Operand<i32>;
3+
def simm4 : Operand<i32> {
4+
let DecoderMethod = "DecodeSimm4";
5+
}
6+
def li_simm7 : Operand<i32> {
7+
let DecoderMethod = "DecodeLiSimm7";
8+
}
59

610
def simm12 : Operand<i32> {
711
let DecoderMethod = "DecodeSimm12";
@@ -13,6 +17,7 @@ def uimm5_lsl2 : Operand<OtherVT> {
1317

1418
def uimm6_lsl2 : Operand<i32> {
1519
let EncoderMethod = "getUImm6Lsl2Encoding";
20+
let DecoderMethod = "DecodeUImm6Lsl2";
1621
}
1722

1823
def simm9_addiusp : Operand<i32> {
@@ -25,6 +30,7 @@ def uimm3_shift : Operand<i32> {
2530

2631
def simm3_lsa2 : Operand<i32> {
2732
let EncoderMethod = "getSImm3Lsa2Value";
33+
let DecoderMethod = "DecodeAddiur2Simm7";
2834
}
2935

3036
def uimm4_andi : Operand<i32> {
@@ -379,7 +385,7 @@ def ADDIUSP_MM : AddImmUSP<"addiusp">, ADDIUSP_FM_MM16;
379385
def MFHI16_MM : MoveFromHILOMM<"mfhi", GPR32Opnd, AC0>, MFHILO_FM_MM16<0x10>;
380386
def MFLO16_MM : MoveFromHILOMM<"mflo", GPR32Opnd, AC0>, MFHILO_FM_MM16<0x12>;
381387
def MOVE16_MM : MoveMM16<"move", GPR32Opnd>, MOVE_FM_MM16<0x03>;
382-
def LI16_MM : LoadImmMM16<"li16", simm7, GPRMM16Opnd, immLi16>,
388+
def LI16_MM : LoadImmMM16<"li16", li_simm7, GPRMM16Opnd, immLi16>,
383389
LI_FM_MM16, IsAsCheapAsAMove;
384390
def JALR16_MM : JumpLinkRegMM16<"jalr", GPR32Opnd>, JALR_FM_MM16<0x0e>;
385391
def JALRS16_MM : JumpLinkRegSMM16<"jalrs16", GPR32Opnd>, JALR_FM_MM16<0x0f>;

llvm/test/MC/Disassembler/Mips/micromips.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,21 @@
390390

391391
# CHECK: jr16 $9
392392
0x45 0x89
393+
394+
# CHECK: li16 $3, -1
395+
0xed 0xff
396+
397+
# CHECK: li16 $3, 126
398+
0xed 0xfe
399+
400+
# CHECK: addiur1sp $7, 4
401+
0x6f 0x83
402+
403+
# CHECK: addiur2 $6, $7, -1
404+
0x6f 0x7e
405+
406+
# CHECK: addiur2 $6, $7, 12
407+
0x6f 0x76
408+
409+
# CHECK: addius5 $7, -2
410+
0x4c 0xfc

llvm/test/MC/Disassembler/Mips/micromips_le.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,21 @@
390390

391391
# CHECK: jr16 $9
392392
0x89 0x45
393+
394+
# CHECK: li16 $3, -1
395+
0xff 0xed
396+
397+
# CHECK: li16 $3, 126
398+
0xfe 0xed
399+
400+
# CHECK: addiur1sp $7, 4
401+
0x83 0x6f
402+
403+
# CHECK: addiur2 $6, $7, -1
404+
0x7e 0x6f
405+
406+
# CHECK: addiur2 $6, $7, 12
407+
0x76 0x6f
408+
409+
# CHECK: addius5 $7, -2
410+
0xfc 0x4c

0 commit comments

Comments
 (0)