bool expandDRotationImm(MCInst &Inst, SMLoc IDLoc,
SmallVectorImpl<MCInst> &Instructions);
+ bool expandAbs(MCInst &Inst, SMLoc IDLoc,
+ SmallVectorImpl<MCInst> &Instructions);
+
void createNop(bool hasShortDelaySlot, SMLoc IDLoc,
SmallVectorImpl<MCInst> &Instructions);
case Mips::DRORImm:
return expandDRotationImm(Inst, IDLoc, Instructions) ? MER_Fail
: MER_Success;
+ case Mips::ABSMacro:
+ return expandAbs(Inst, IDLoc, Instructions) ? MER_Fail
+ : MER_Success;
}
}
return true;
}
+bool MipsAsmParser::expandAbs(MCInst &Inst, SMLoc IDLoc,
+ SmallVectorImpl<MCInst> &Instructions) {
+
+ unsigned FirstRegOp = Inst.getOperand(0).getReg();
+ unsigned SecondRegOp = Inst.getOperand(1).getReg();
+
+ emitRI(Mips::BGEZ, SecondRegOp, 8, IDLoc, Instructions);
+ if (FirstRegOp != SecondRegOp)
+ emitRRR(Mips::ADDu, FirstRegOp, SecondRegOp, Mips::ZERO, IDLoc, Instructions);
+ else
+ createNop(false, IDLoc, Instructions);
+ emitRRR(Mips::SUB, FirstRegOp, Mips::ZERO, SecondRegOp, IDLoc, Instructions);
+
+ return false;
+}
+
void MipsAsmParser::createNop(bool hasShortDelaySlot, SMLoc IDLoc,
SmallVectorImpl<MCInst> &Instructions) {
if (hasShortDelaySlot)
def : MipsInstAlias<"dror $rd, $imm",
(DRORImm GPR32Opnd:$rd, GPR32Opnd:$rd, simm16:$imm), 0>, ISA_MIPS64;
+def ABSMacro : MipsAsmPseudoInst<(outs GPR32Opnd:$rd), (ins GPR32Opnd:$rs),
+ "abs\t$rd, $rs">;
+
//===----------------------------------------------------------------------===//
// Instruction aliases
//===----------------------------------------------------------------------===//
--- /dev/null
+# RUN: llvm-mc -triple mips-unknown-linux -show-encoding %s | FileCheck %s
+
+.text
+# CHECK: .text
+ abs $4, $4
+# CHECK: bgez $4, 8 # encoding: [0x04,0x81,0x00,0x02]
+# CHECK: nop # encoding: [0x00,0x00,0x00,0x00]
+# CHECK: neg $4, $4 # encoding: [0x00,0x04,0x20,0x22]
+ abs $4, $5
+# CHECK: bgez $5, 8 # encoding: [0x04,0xa1,0x00,0x02]
+# CHECK: move $4, $5 # encoding: [0x00,0xa0,0x20,0x21]
+# CHECK: neg $4, $5 # encoding: [0x00,0x05,0x20,0x22]