diff options
Diffstat (limited to 'llvm/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp')
-rw-r--r-- | llvm/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp | 57 |
1 files changed, 8 insertions, 49 deletions
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp index d043bdf6fdd..3150517107e 100644 --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp @@ -653,61 +653,20 @@ getMachineOpValue(const MCInst &MI, const MCOperand &MO, return getExprOpValue(MO.getExpr(),Fixups, STI); } -/// getMSAMemEncoding - Return binary encoding of memory operand for LD/ST -/// instructions. -unsigned -MipsMCCodeEmitter::getMSAMemEncoding(const MCInst &MI, unsigned OpNo, - SmallVectorImpl<MCFixup> &Fixups, - const MCSubtargetInfo &STI) const { - // Base register is encoded in bits 20-16, offset is encoded in bits 15-0. - assert(MI.getOperand(OpNo).isReg()); - unsigned RegBits = getMachineOpValue(MI, MI.getOperand(OpNo),Fixups, STI) << 16; - unsigned OffBits = getMachineOpValue(MI, MI.getOperand(OpNo+1), Fixups, STI); - - // The immediate field of an LD/ST instruction is scaled which means it must - // be divided (when encoding) by the size (in bytes) of the instructions' - // data format. - // .b - 1 byte - // .h - 2 bytes - // .w - 4 bytes - // .d - 8 bytes - switch(MI.getOpcode()) - { - default: - assert (0 && "Unexpected instruction"); - break; - case Mips::LD_B: - case Mips::ST_B: - // We don't need to scale the offset in this case - break; - case Mips::LD_H: - case Mips::ST_H: - OffBits >>= 1; - break; - case Mips::LD_W: - case Mips::ST_W: - OffBits >>= 2; - break; - case Mips::LD_D: - case Mips::ST_D: - OffBits >>= 3; - break; - } - - return (OffBits & 0xFFFF) | RegBits; -} - -/// getMemEncoding - Return binary encoding of memory related operand. +/// Return binary encoding of memory related operand. /// If the offset operand requires relocation, record the relocation. -unsigned -MipsMCCodeEmitter::getMemEncoding(const MCInst &MI, unsigned OpNo, - SmallVectorImpl<MCFixup> &Fixups, - const MCSubtargetInfo &STI) const { +template <unsigned ShiftAmount> +unsigned MipsMCCodeEmitter::getMemEncoding(const MCInst &MI, unsigned OpNo, + SmallVectorImpl<MCFixup> &Fixups, + const MCSubtargetInfo &STI) const { // Base register is encoded in bits 20-16, offset is encoded in bits 15-0. assert(MI.getOperand(OpNo).isReg()); unsigned RegBits = getMachineOpValue(MI, MI.getOperand(OpNo),Fixups, STI) << 16; unsigned OffBits = getMachineOpValue(MI, MI.getOperand(OpNo+1), Fixups, STI); + // Apply the scale factor if there is one. + OffBits >>= ShiftAmount; + return (OffBits & 0xFFFF) | RegBits; } |