Skip to content

Commit ab1046b

Browse files
authored
[AVR] Refactor MUL/FMUL instruction descriptions (NFC) (#156862)
* Split MULSU format from MULS and fix the comment * Remove custom decoder functions for the instructions * Add a decoder for LD8lo register class
1 parent ba4ce60 commit ab1046b

File tree

3 files changed

+38
-46
lines changed

3 files changed

+38
-46
lines changed

llvm/lib/Target/AVR/AVRInstrFormats.td

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -228,22 +228,37 @@ class FMOVWRdRr<dag outs, dag ins, string asmstr, list<dag> pattern>
228228
}
229229

230230
//===----------------------------------------------------------------------===//
231-
// MULSrr special encoding: <|0000|0010|dddd|rrrr|>
231+
// MULS special encoding: <|0000|0010|dddd|rrrr|>
232232
// d = multiplicand = 4 bits
233233
// r = multiplier = 4 bits
234234
// (Only accepts r16-r31)
235235
//===----------------------------------------------------------------------===//
236-
class FMUL2RdRr<bit f, dag outs, dag ins, string asmstr, list<dag> pattern>
236+
class FMULSRdRr<dag outs, dag ins, string asmstr, list<dag> pattern>
237237
: AVRInst16<outs, ins, asmstr, pattern> {
238-
bits<5> rd; // accept 5 bits but only encode the lower 4
239-
bits<5> rr; // accept 5 bits but only encode the lower 4
238+
bits<4> rd;
239+
bits<4> rr;
240240

241-
let Inst{15 - 9} = 0b0000001;
242-
let Inst{8} = f;
243-
let Inst{7 - 4} = rd{3 - 0};
244-
let Inst{3 - 0} = rr{3 - 0};
241+
let Inst{15 - 8} = 0b00000010;
242+
let Inst{7 - 4} = rd;
243+
let Inst{3 - 0} = rr;
244+
}
245+
246+
//===----------------------------------------------------------------------===//
247+
// MULSU special encoding: <|0000|0011|0ddd|0rrr|>
248+
// d = multiplicand = 3 bits
249+
// r = multiplier = 3 bits
250+
// (Only accepts r16-r23)
251+
//===----------------------------------------------------------------------===//
252+
class FMULSURdRr<dag outs, dag ins, string asmstr, list<dag> pattern>
253+
: AVRInst16<outs, ins, asmstr, pattern> {
254+
bits<3> rd;
255+
bits<3> rr;
245256

246-
let DecoderMethod = "decodeFMUL2RdRr";
257+
let Inst{15 - 8} = 0b00000011;
258+
let Inst{7} = 0;
259+
let Inst{6 - 4} = rd;
260+
let Inst{3} = 0;
261+
let Inst{2 - 0} = rr;
247262
}
248263

249264
// Special encoding for the FMUL family of instructions.
@@ -266,8 +281,6 @@ class FFMULRdRr<bits<2> f, dag outs, dag ins, string asmstr, list<dag> pattern>
266281
let Inst{6 - 4} = rd;
267282
let Inst{3} = f{0};
268283
let Inst{2 - 0} = rr;
269-
270-
let DecoderMethod = "decodeFFMULRdRr";
271284
}
272285

273286
//===----------------------------------------------------------------------===//

llvm/lib/Target/AVR/AVRInstrInfo.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,13 +495,13 @@ let isCommutable = 1, Defs = [R1, R0, SREG] in {
495495
"mul\t$rd, $rr", []>,
496496
Requires<[SupportsMultiplication]>;
497497

498-
def MULSRdRr : FMUL2RdRr<0, (outs), (ins LD8:$rd, LD8:$rr),
498+
def MULSRdRr : FMULSRdRr<(outs), (ins LD8:$rd, LD8:$rr),
499499
"muls\t$rd, $rr", []>,
500500
Requires<[SupportsMultiplication]>;
501501
}
502502

503-
def MULSURdRr : FMUL2RdRr<1, (outs), (ins LD8lo:$rd, LD8lo:$rr),
504-
"mulsu\t$rd, $rr", []>,
503+
def MULSURdRr : FMULSURdRr<(outs), (ins LD8lo:$rd, LD8lo:$rr),
504+
"mulsu\t$rd, $rr", []>,
505505
Requires<[SupportsMultiplication]>;
506506

507507
def FMUL : FFMULRdRr<0b01, (outs), (ins LD8lo:$rd, LD8lo:$rr),

llvm/lib/Target/AVR/Disassembler/AVRDisassembler.cpp

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,18 @@ static DecodeStatus DecodeGPR8RegisterClass(MCInst &Inst, unsigned RegNo,
8383
static DecodeStatus DecodeLD8RegisterClass(MCInst &Inst, unsigned RegNo,
8484
uint64_t Address,
8585
const MCDisassembler *Decoder) {
86-
if (RegNo > 15)
87-
return MCDisassembler::Fail;
86+
assert(isUInt<4>(RegNo));
87+
// Only r16...r31 are legal.
88+
Inst.addOperand(MCOperand::createReg(GPRDecoderTable[16 + RegNo]));
89+
return MCDisassembler::Success;
90+
}
8891

89-
unsigned Register = GPRDecoderTable[RegNo + 16];
90-
Inst.addOperand(MCOperand::createReg(Register));
92+
static DecodeStatus DecodeLD8loRegisterClass(MCInst &Inst, unsigned RegNo,
93+
uint64_t Address,
94+
const MCDisassembler *Decoder) {
95+
assert(isUInt<3>(RegNo));
96+
// Only r16...r23 are legal.
97+
Inst.addOperand(MCOperand::createReg(GPRDecoderTable[16 + RegNo]));
9198
return MCDisassembler::Success;
9299
}
93100

@@ -122,20 +129,6 @@ static DecodeStatus decodeRelCondBrTarget13(MCInst &Inst, unsigned Field,
122129
return MCDisassembler::Success;
123130
}
124131

125-
static DecodeStatus decodeFFMULRdRr(MCInst &Inst, unsigned Insn,
126-
uint64_t Address,
127-
const MCDisassembler *Decoder) {
128-
unsigned d = fieldFromInstruction(Insn, 4, 3) + 16;
129-
unsigned r = fieldFromInstruction(Insn, 0, 3) + 16;
130-
if (DecodeGPR8RegisterClass(Inst, d, Address, Decoder) ==
131-
MCDisassembler::Fail)
132-
return MCDisassembler::Fail;
133-
if (DecodeGPR8RegisterClass(Inst, r, Address, Decoder) ==
134-
MCDisassembler::Fail)
135-
return MCDisassembler::Fail;
136-
return MCDisassembler::Success;
137-
}
138-
139132
static DecodeStatus decodeFMOVWRdRr(MCInst &Inst, unsigned Insn,
140133
uint64_t Address,
141134
const MCDisassembler *Decoder) {
@@ -166,20 +159,6 @@ static DecodeStatus decodeFWRdK(MCInst &Inst, unsigned Insn, uint64_t Address,
166159
return MCDisassembler::Success;
167160
}
168161

169-
static DecodeStatus decodeFMUL2RdRr(MCInst &Inst, unsigned Insn,
170-
uint64_t Address,
171-
const MCDisassembler *Decoder) {
172-
unsigned rd = fieldFromInstruction(Insn, 4, 4) + 16;
173-
unsigned rr = fieldFromInstruction(Insn, 0, 4) + 16;
174-
if (DecodeGPR8RegisterClass(Inst, rd, Address, Decoder) ==
175-
MCDisassembler::Fail)
176-
return MCDisassembler::Fail;
177-
if (DecodeGPR8RegisterClass(Inst, rr, Address, Decoder) ==
178-
MCDisassembler::Fail)
179-
return MCDisassembler::Fail;
180-
return MCDisassembler::Success;
181-
}
182-
183162
static DecodeStatus decodeMemri(MCInst &Inst, unsigned Insn, uint64_t Address,
184163
const MCDisassembler *Decoder) {
185164
// As in the EncoderMethod `AVRMCCodeEmitter::encodeMemri`, the memory

0 commit comments

Comments
 (0)