Skip to content

Commit a6593ff

Browse files
author
Zoran Jovanovic
committed
[mips][microMIPS] Implement SW and SWE instructions
Differential Revision: http://reviews.llvm.org/D10869 llvm-svn: 245293
1 parent 4eb8257 commit a6593ff

File tree

7 files changed

+105
-0
lines changed

7 files changed

+105
-0
lines changed

llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,10 @@ class MipsOperand : public MCParsedAsmOperand {
951951
template <unsigned Bits> bool isMemWithSimmOffset() const {
952952
return isMem() && isConstantMemOff() && isInt<Bits>(getConstantMemOff());
953953
}
954+
template <unsigned Bits> bool isMemWithSimmOffsetGPR() const {
955+
return isMem() && isConstantMemOff() && isInt<Bits>(getConstantMemOff())
956+
&& getMemBase()->isGPRAsmReg();
957+
}
954958
bool isMemWithGRPMM16Base() const {
955959
return isMem() && getMemBase()->isMM16AsmReg();
956960
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ static DecodeStatus DecodeMemMMReglistImm4Lsl2(MCInst &Inst,
284284
uint64_t Address,
285285
const void *Decoder);
286286

287+
static DecodeStatus DecodeMemMMImm9(MCInst &Inst,
288+
unsigned Insn,
289+
uint64_t Address,
290+
const void *Decoder);
291+
287292
static DecodeStatus DecodeMemMMImm12(MCInst &Inst,
288293
unsigned Insn,
289294
uint64_t Address,
@@ -1304,6 +1309,24 @@ static DecodeStatus DecodeMemMMReglistImm4Lsl2(MCInst &Inst,
13041309
return MCDisassembler::Success;
13051310
}
13061311

1312+
static DecodeStatus DecodeMemMMImm9(MCInst &Inst,
1313+
unsigned Insn,
1314+
uint64_t Address,
1315+
const void *Decoder) {
1316+
int Offset = SignExtend32<9>(Insn & 0x1ff);
1317+
unsigned Reg = fieldFromInstruction(Insn, 21, 5);
1318+
unsigned Base = fieldFromInstruction(Insn, 16, 5);
1319+
1320+
Reg = getReg(Decoder, Mips::GPR32RegClassID, Reg);
1321+
Base = getReg(Decoder, Mips::GPR32RegClassID, Base);
1322+
1323+
Inst.addOperand(MCOperand::createReg(Reg));
1324+
Inst.addOperand(MCOperand::createReg(Base));
1325+
Inst.addOperand(MCOperand::createImm(Offset));
1326+
1327+
return MCDisassembler::Success;
1328+
}
1329+
13071330
static DecodeStatus DecodeMemMMImm12(MCInst &Inst,
13081331
unsigned Insn,
13091332
uint64_t Address,

llvm/lib/Target/Mips/MicroMips32r6InstrFormats.td

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,33 @@ class SHIFT_MMR6_ENC<string instr_asm, bits<10> funct, bit rotate> : MMR6Arch<in
287287
let Inst{10} = rotate;
288288
let Inst{9-0} = funct;
289289
}
290+
291+
class SW32_FM_MMR6<string instr_asm, bits<6> op> : MMR6Arch<instr_asm> {
292+
bits<5> rt;
293+
bits<21> addr;
294+
295+
bits<32> Inst;
296+
297+
let Inst{31-26} = op;
298+
let Inst{25-21} = rt;
299+
let Inst{20-16} = addr{20-16};
300+
let Inst{15-0} = addr{15-0};
301+
}
302+
303+
class POOL32C_SWE_FM_MMR6<string instr_asm, bits<6> op, bits<4> fmt,
304+
bits<3> funct> : MMR6Arch<instr_asm> {
305+
bits<5> rt;
306+
bits<21> addr;
307+
bits<5> base = addr{20-16};
308+
bits<9> offset = addr{8-0};
309+
310+
bits<32> Inst;
311+
312+
let Inst{31-26} = op;
313+
let Inst{25-21} = rt;
314+
let Inst{20-16} = base;
315+
let Inst{15-12} = fmt;
316+
let Inst{11-9} = funct;
317+
let Inst{8-0} = offset;
318+
}
319+

llvm/lib/Target/Mips/MicroMips32r6InstrInfo.td

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class SELNEZ_MMR6_ENC : POOL32A_FM_MMR6<0b0110000000>;
6666
class SLL_MMR6_ENC : SHIFT_MMR6_ENC<"sll", 0x00, 0b0>;
6767
class SUB_MMR6_ENC : ARITH_FM_MMR6<"sub", 0x190>;
6868
class SUBU_MMR6_ENC : ARITH_FM_MMR6<"subu", 0x1d0>;
69+
class SW_MMR6_ENC : SW32_FM_MMR6<"sw", 0x3e>;
70+
class SWE_MMR6_ENC : POOL32C_SWE_FM_MMR6<"swe", 0x18, 0xa, 0x7>;
6971
class XOR_MMR6_ENC : ARITH_FM_MMR6<"xor", 0x310>;
7072
class XORI_MMR6_ENC : ADDI_FM_MMR6<"xori", 0x1c>;
7173

@@ -108,6 +110,26 @@ class BNEZALC_MMR6_DESC : CMP_CBR_RT_Z_MMR6_DESC_BASE<"bnezalc", brtarget_mm,
108110
list<Register> Defs = [RA];
109111
}
110112

113+
//===----------------------------------------------------------------------===//
114+
//
115+
// Operand Definitions
116+
//
117+
//===----------------------------------------------------------------------===//
118+
119+
def MipsMemSimm9GPRAsmOperand : AsmOperandClass {
120+
let Name = "MemOffsetSimm9GPR";
121+
let SuperClasses = [MipsMemAsmOperand];
122+
let RenderMethod = "addMemOperands";
123+
let ParserMethod = "parseMemOperand";
124+
let PredicateMethod = "isMemWithSimmOffsetGPR<9>";
125+
}
126+
127+
def mem_simm9gpr : mem_generic {
128+
let MIOperandInfo = (ops ptr_rc, simm9);
129+
let EncoderMethod = "getMemEncoding";
130+
let ParserMatchClass = MipsMemSimm9GPRAsmOperand;
131+
}
132+
111133
//===----------------------------------------------------------------------===//
112134
//
113135
// Instruction Descriptions
@@ -277,6 +299,18 @@ class ORI_MMR6_DESC : ArithLogicI<"ori", simm16, GPR32Opnd>;
277299
class XOR_MMR6_DESC : ArithLogicR<"xor", GPR32Opnd>;
278300
class XORI_MMR6_DESC : ArithLogicI<"xori", simm16, GPR32Opnd>;
279301

302+
class SWE_MMR6_DESC_BASE<string opstr, DAGOperand RO, DAGOperand MO,
303+
SDPatternOperator OpNode = null_frag,
304+
InstrItinClass Itin = NoItinerary,
305+
ComplexPattern Addr = addr> :
306+
InstSE<(outs), (ins RO:$rt, MO:$addr), !strconcat(opstr, "\t$rt, $addr"),
307+
[(OpNode RO:$rt, Addr:$addr)], Itin, FrmI, opstr> {
308+
let DecoderMethod = "DecodeMem";
309+
let mayStore = 1;
310+
}
311+
class SW_MMR6_DESC : Store<"sw", GPR32Opnd>;
312+
class SWE_MMR6_DESC : SWE_MMR6_DESC_BASE<"swe", GPR32Opnd, mem_simm9gpr>;
313+
280314
//===----------------------------------------------------------------------===//
281315
//
282316
// Instruction Definitions
@@ -348,6 +382,12 @@ def SUB_MMR6 : StdMMR6Rel, SUB_MMR6_DESC, SUB_MMR6_ENC, ISA_MICROMIPS32R6;
348382
def SUBU_MMR6 : StdMMR6Rel, SUBU_MMR6_DESC, SUBU_MMR6_ENC, ISA_MICROMIPS32R6;
349383
def XOR_MMR6 : StdMMR6Rel, XOR_MMR6_DESC, XOR_MMR6_ENC, ISA_MICROMIPS32R6;
350384
def XORI_MMR6 : StdMMR6Rel, XORI_MMR6_DESC, XORI_MMR6_ENC, ISA_MICROMIPS32R6;
385+
let DecoderMethod = "DecodeMemMMImm16" in {
386+
def SW_MMR6 : StdMMR6Rel, SW_MMR6_DESC, SW_MMR6_ENC, ISA_MICROMIPS32R6;
387+
}
388+
let DecoderMethod = "DecodeMemMMImm9" in {
389+
def SWE_MMR6 : StdMMR6Rel, SWE_MMR6_DESC, SWE_MMR6_ENC, ISA_MICROMIPS32R6;
390+
}
351391
}
352392

353393
//===----------------------------------------------------------------------===//

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,6 @@
112112

113113
0x00 0x64 0x3b 0x3c # CHECK: seh $3, $4
114114

115+
0xf8,0xa6,0x00,0x04 # CHECK: sw $5, 4($6)
116+
117+
0x60,0xa4,0xae,0x08 # CHECK: swe $5, 8($4)

llvm/test/MC/Mips/micromips32r6/invalid.s

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
break 1024 # CHECK: :[[@LINE]]:{{[0-9]+}}: error: invalid operand for instruction
55
break 1023, 1024 # CHECK: :[[@LINE]]:{{[0-9]+}}: error: invalid operand for instruction
66
ei $32 # CHECK: :[[@LINE]]:{{[0-9]+}}: error: invalid operand for instruction
7+
swe $33, 8($4) # CHECK: :[[@LINE]]:{{[0-9]+}}: error: invalid operand for instruction
8+
swe $5, 8($34) # CHECK: :[[@LINE]]:{{[0-9]+}}: error: invalid operand for instruction
9+
swe $5, 512($4) # CHECK: :[[@LINE]]:{{[0-9]+}}: error: invalid operand for instruction

llvm/test/MC/Mips/micromips32r6/valid.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,6 @@
5858
subu $3, $4, $5 # CHECK: subu $3, $4, $5 # encoding: [0x00,0xa4,0x19,0xd0]
5959
xor $3, $4, $5 # CHECK: xor $3, $4, $5 # encoding: [0x00,0xa4,0x1b,0x10]
6060
xori $3, $4, 1234 # CHECK: xori $3, $4, 1234 # encoding: [0x70,0x64,0x04,0xd2]
61+
sw $5, 4($6) # CHECK: sw $5, 4($6) # encoding: [0xf8,0xa6,0x00,0x04]
62+
swe $5, 8($4) # CHECK: swe $5, 8($4) # encoding: [0x60,0xa4,0xae,0x08]
6163

0 commit comments

Comments
 (0)