Index: lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.h =================================================================== --- lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.h +++ lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.h @@ -80,6 +80,12 @@ SmallVectorImpl &Fixups, const MCSubtargetInfo &STI) const; + // getAddius5Value - Return binary encoding of the microMIPS jump + // target operand. + unsigned getAddius5Value(const MCInst &MI, unsigned OpNo, + SmallVectorImpl &Fixups, + const MCSubtargetInfo &STI) const; + // getBranchTargetOpValue - Return binary encoding of the branch // target operand. If the machine operand requires relocation, // record the relocation and return zero. Index: lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp =================================================================== --- lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp +++ lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp @@ -360,6 +360,17 @@ } unsigned MipsMCCodeEmitter:: +getAddius5Value(const MCInst &MI, unsigned OpNo, + SmallVectorImpl &Fixups, + const MCSubtargetInfo &STI) const { + + const MCOperand &MO = MI.getOperand(OpNo); + if (MO.isImm()) return MO.getImm() & 0xf; + + return 0; +} + +unsigned MipsMCCodeEmitter:: getExprOpValue(const MCExpr *Expr,SmallVectorImpl &Fixups, const MCSubtargetInfo &STI) const { int64_t Res; Index: lib/Target/Mips/MicroMipsInstrFormats.td =================================================================== --- lib/Target/Mips/MicroMipsInstrFormats.td +++ lib/Target/Mips/MicroMipsInstrFormats.td @@ -41,6 +41,18 @@ // MicroMIPS 16-bit Instruction Formats //===----------------------------------------------------------------------===// +class ADDIUS5_FM_MM16 { + bits<5> rd; + bits<4> imm; + + bits<16> Inst; + + let Inst{15-10} = 0x13; + let Inst{9-5} = rd; + let Inst{4-1} = imm; + let Inst{0} = 0; +} + class MOVE_FM_MM16 funct> { bits<5> rs; bits<5> rd; Index: lib/Target/Mips/MicroMipsInstrInfo.td =================================================================== --- lib/Target/Mips/MicroMipsInstrInfo.td +++ lib/Target/Mips/MicroMipsInstrInfo.td @@ -8,6 +8,10 @@ let EncoderMethod = "getImm5Shr2Value"; } +def addius5_imm : Operand { + let EncoderMethod = "getAddius5Value"; +} + def mem_mm_12 : Operand { let PrintMethod = "printMemOperand"; let MIOperandInfo = (ops GPR32, simm12); @@ -84,6 +88,13 @@ let mayLoad = 1; } +class AddImmUS5 : + MicroMipsInst16<(outs RO:$dst), (ins RO:$rd, addius5_imm:$imm), + !strconcat(opstr, "\t$rd, $imm"), [], NoItinerary, FrmR> { + let Constraints = "$rd = $dst"; + let isCommutable = 1; +} + class MoveFromHILOMM : MicroMipsInst16<(outs RO:$rd), (ins), !strconcat(opstr, "\t$rd"), [], II_MFHI_MFLO, FrmR> { @@ -154,6 +165,7 @@ !strconcat(opstr, "\t$rs, $offset"), [], IIBranch, FrmI, opstr>; } +def ADDIUS5_MM : AddImmUS5<"addius5", GPR32Opnd>, ADDIUS5_FM_MM16; 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>; Index: lib/Target/Mips/MipsCodeEmitter.cpp =================================================================== --- lib/Target/Mips/MipsCodeEmitter.cpp +++ lib/Target/Mips/MipsCodeEmitter.cpp @@ -108,6 +108,7 @@ unsigned getJumpTargetOpValue(const MachineInstr &MI, unsigned OpNo) const; unsigned getJumpTargetOpValueMM(const MachineInstr &MI, unsigned OpNo) const; unsigned getImm5Shr2Value(const MachineInstr &MI, unsigned OpNo) const; + unsigned getAddius5Value(const MachineInstr &MI, unsigned OpNo) const; unsigned getBranchTargetOpValueMM(const MachineInstr &MI, unsigned OpNo) const; @@ -215,6 +216,12 @@ return 0; } +unsigned MipsCodeEmitter::getAddius5Value(const MachineInstr &MI, + unsigned OpNo) const { + llvm_unreachable("Unimplemented function."); + return 0; +} + unsigned MipsCodeEmitter::getBranchTargetOpValueMM(const MachineInstr &MI, unsigned OpNo) const { llvm_unreachable("Unimplemented function."); Index: test/MC/Mips/micromips-16-bit-instructions.s =================================================================== --- test/MC/Mips/micromips-16-bit-instructions.s +++ test/MC/Mips/micromips-16-bit-instructions.s @@ -9,6 +9,7 @@ #------------------------------------------------------------------------------ # Little endian #------------------------------------------------------------------------------ +# CHECK-EL: addius5 $7, -2 # encoding: [0xfc,0x4c] # CHECK-EL: mfhi $9 # encoding: [0x09,0x46] # CHECK-EL: mflo $9 # encoding: [0x49,0x46] # CHECK-EL: move $25, $1 # encoding: [0x21,0x0f] @@ -22,6 +23,7 @@ #------------------------------------------------------------------------------ # Big endian #------------------------------------------------------------------------------ +# CHECK-EB: addius5 $7, -2 # encoding: [0x4c,0xfc] # CHECK-EB: mfhi $9 # encoding: [0x46,0x09] # CHECK-EB: mflo $9 # encoding: [0x46,0x49] # CHECK-EB: move $25, $1 # encoding: [0x0f,0x21] @@ -33,6 +35,7 @@ # CHECK-EB: jraddiusp 20 # encoding: [0x47,0x05] # CHECK-EB: nop # encoding: [0x00,0x00,0x00,0x00] + addius5 $7, -2 mfhi $9 mflo $9 move $25, $1