Index: llvm/trunk/lib/Target/Mips/Disassembler/MipsDisassembler.cpp =================================================================== --- llvm/trunk/lib/Target/Mips/Disassembler/MipsDisassembler.cpp +++ llvm/trunk/lib/Target/Mips/Disassembler/MipsDisassembler.cpp @@ -287,6 +287,26 @@ uint64_t Address, const void *Decoder); +static DecodeStatus DecodeAddiur2Simm7(MCInst &Inst, + unsigned Value, + uint64_t Address, + const void *Decoder); + +static DecodeStatus DecodeUImm6Lsl2(MCInst &Inst, + unsigned Value, + uint64_t Address, + const void *Decoder); + +static DecodeStatus DecodeLiSimm7(MCInst &Inst, + unsigned Value, + uint64_t Address, + const void *Decoder); + +static DecodeStatus DecodeSimm4(MCInst &Inst, + unsigned Value, + uint64_t Address, + const void *Decoder); + static DecodeStatus DecodeSimm16(MCInst &Inst, unsigned Insn, uint64_t Address, @@ -1458,6 +1478,46 @@ return MCDisassembler::Success; } +static DecodeStatus DecodeAddiur2Simm7(MCInst &Inst, + unsigned Value, + uint64_t Address, + const void *Decoder) { + if (Value == 0) + Inst.addOperand(MCOperand::CreateImm(1)); + else if (Value == 0x7) + Inst.addOperand(MCOperand::CreateImm(-1)); + else + Inst.addOperand(MCOperand::CreateImm(Value << 2)); + return MCDisassembler::Success; +} + +static DecodeStatus DecodeUImm6Lsl2(MCInst &Inst, + unsigned Value, + uint64_t Address, + const void *Decoder) { + Inst.addOperand(MCOperand::CreateImm(Value << 2)); + return MCDisassembler::Success; +} + +static DecodeStatus DecodeLiSimm7(MCInst &Inst, + unsigned Value, + uint64_t Address, + const void *Decoder) { + if (Value == 0x7F) + Inst.addOperand(MCOperand::CreateImm(-1)); + else + Inst.addOperand(MCOperand::CreateImm(Value)); + return MCDisassembler::Success; +} + +static DecodeStatus DecodeSimm4(MCInst &Inst, + unsigned Value, + uint64_t Address, + const void *Decoder) { + Inst.addOperand(MCOperand::CreateImm(SignExtend32<4>(Value))); + return MCDisassembler::Success; +} + static DecodeStatus DecodeSimm16(MCInst &Inst, unsigned Insn, uint64_t Address, Index: llvm/trunk/lib/Target/Mips/MicroMipsInstrInfo.td =================================================================== --- llvm/trunk/lib/Target/Mips/MicroMipsInstrInfo.td +++ llvm/trunk/lib/Target/Mips/MicroMipsInstrInfo.td @@ -1,7 +1,11 @@ def addrimm12 : ComplexPattern; -def simm4 : Operand; -def simm7 : Operand; +def simm4 : Operand { + let DecoderMethod = "DecodeSimm4"; +} +def li_simm7 : Operand { + let DecoderMethod = "DecodeLiSimm7"; +} def simm12 : Operand { let DecoderMethod = "DecodeSimm12"; @@ -13,6 +17,7 @@ def uimm6_lsl2 : Operand { let EncoderMethod = "getUImm6Lsl2Encoding"; + let DecoderMethod = "DecodeUImm6Lsl2"; } def simm9_addiusp : Operand { @@ -25,6 +30,7 @@ def simm3_lsa2 : Operand { let EncoderMethod = "getSImm3Lsa2Value"; + let DecoderMethod = "DecodeAddiur2Simm7"; } def uimm4_andi : Operand { @@ -379,7 +385,7 @@ def MFHI16_MM : MoveFromHILOMM<"mfhi", GPR32Opnd, AC0>, MFHILO_FM_MM16<0x10>; def MFLO16_MM : MoveFromHILOMM<"mflo", GPR32Opnd, AC0>, MFHILO_FM_MM16<0x12>; def MOVE16_MM : MoveMM16<"move", GPR32Opnd>, MOVE_FM_MM16<0x03>; -def LI16_MM : LoadImmMM16<"li16", simm7, GPRMM16Opnd, immLi16>, +def LI16_MM : LoadImmMM16<"li16", li_simm7, GPRMM16Opnd, immLi16>, LI_FM_MM16, IsAsCheapAsAMove; def JALR16_MM : JumpLinkRegMM16<"jalr", GPR32Opnd>, JALR_FM_MM16<0x0e>; def JALRS16_MM : JumpLinkRegSMM16<"jalrs16", GPR32Opnd>, JALR_FM_MM16<0x0f>; Index: llvm/trunk/test/MC/Disassembler/Mips/micromips.txt =================================================================== --- llvm/trunk/test/MC/Disassembler/Mips/micromips.txt +++ llvm/trunk/test/MC/Disassembler/Mips/micromips.txt @@ -390,3 +390,21 @@ # CHECK: jr16 $9 0x45 0x89 + +# CHECK: li16 $3, -1 +0xed 0xff + +# CHECK: li16 $3, 126 +0xed 0xfe + +# CHECK: addiur1sp $7, 4 +0x6f 0x83 + +# CHECK: addiur2 $6, $7, -1 +0x6f 0x7e + +# CHECK: addiur2 $6, $7, 12 +0x6f 0x76 + +# CHECK: addius5 $7, -2 +0x4c 0xfc Index: llvm/trunk/test/MC/Disassembler/Mips/micromips_le.txt =================================================================== --- llvm/trunk/test/MC/Disassembler/Mips/micromips_le.txt +++ llvm/trunk/test/MC/Disassembler/Mips/micromips_le.txt @@ -390,3 +390,21 @@ # CHECK: jr16 $9 0x89 0x45 + +# CHECK: li16 $3, -1 +0xff 0xed + +# CHECK: li16 $3, 126 +0xfe 0xed + +# CHECK: addiur1sp $7, 4 +0x83 0x6f + +# CHECK: addiur2 $6, $7, -1 +0x7e 0x6f + +# CHECK: addiur2 $6, $7, 12 +0x76 0x6f + +# CHECK: addius5 $7, -2 +0xfc 0x4c