Emit Rshamt-type instructions for RISC-V.
These are the shift-by-immediate instructions.
This commit is contained in:
@@ -55,9 +55,15 @@ ebb0:
|
|||||||
[-,%x7] v114 = bxor_imm v1, 1000 ; bin: 3e854393
|
[-,%x7] v114 = bxor_imm v1, 1000 ; bin: 3e854393
|
||||||
[-,%x16] v115 = bxor_imm v2, -905 ; bin: c77ac813
|
[-,%x16] v115 = bxor_imm v2, -905 ; bin: c77ac813
|
||||||
|
|
||||||
; TBD: slli
|
; slli
|
||||||
; TBD: srli
|
[-,%x7] v120 = ishl_imm v1, 31 ; bin: 01f51393
|
||||||
; TBD: srai
|
[-,%x16] v121 = ishl_imm v2, 8 ; bin: 008a9813
|
||||||
|
; srli
|
||||||
|
[-,%x7] v122 = ushr_imm v1, 31 ; bin: 01f55393
|
||||||
|
[-,%x16] v123 = ushr_imm v2, 8 ; bin: 008ad813
|
||||||
|
; srai
|
||||||
|
[-,%x7] v124 = sshr_imm v1, 31 ; bin: 41f55393
|
||||||
|
[-,%x16] v125 = sshr_imm v2, 8 ; bin: 408ad813
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,40 @@ fn put_r<CS: CodeSink + ?Sized>(bits: u16,
|
|||||||
sink.put4(i);
|
sink.put4(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// R-type instructions with a shift amount instead of rs2.
|
||||||
|
///
|
||||||
|
/// 31 25 19 14 11 6
|
||||||
|
/// funct7 shamt rs1 funct3 rd opcode
|
||||||
|
/// 25 20 15 12 7 0
|
||||||
|
///
|
||||||
|
/// Both funct7 and shamt contribute to bit 25. In RV64, shamt uses it for shifts > 31.
|
||||||
|
///
|
||||||
|
/// Encoding bits: `opcode[6:2] | (funct3 << 5) | (funct7 << 8)`.
|
||||||
|
fn put_rshamt<CS: CodeSink + ?Sized>(bits: u16,
|
||||||
|
rs1: RegUnit,
|
||||||
|
shamt: i64,
|
||||||
|
rd: RegUnit,
|
||||||
|
sink: &mut CS) {
|
||||||
|
let bits = bits as u32;
|
||||||
|
let opcode5 = bits & 0x1f;
|
||||||
|
let funct3 = (bits >> 5) & 0x7;
|
||||||
|
let funct7 = (bits >> 8) & 0x7f;
|
||||||
|
let rs1 = rs1 as u32 & 0x1f;
|
||||||
|
let shamt = shamt as u32 & 0x3f;
|
||||||
|
let rd = rd as u32 & 0x1f;
|
||||||
|
|
||||||
|
// 0-6: opcode
|
||||||
|
let mut i = 0x3;
|
||||||
|
i |= opcode5 << 2;
|
||||||
|
i |= rd << 7;
|
||||||
|
i |= funct3 << 12;
|
||||||
|
i |= rs1 << 15;
|
||||||
|
i |= shamt << 20;
|
||||||
|
i |= funct7 << 25;
|
||||||
|
|
||||||
|
sink.put4(i);
|
||||||
|
}
|
||||||
|
|
||||||
fn recipe_r<CS: CodeSink + ?Sized>(func: &Function, inst: Inst, sink: &mut CS) {
|
fn recipe_r<CS: CodeSink + ?Sized>(func: &Function, inst: Inst, sink: &mut CS) {
|
||||||
if let InstructionData::Binary { args, .. } = func.dfg[inst] {
|
if let InstructionData::Binary { args, .. } = func.dfg[inst] {
|
||||||
put_r(func.encodings[inst].bits(),
|
put_r(func.encodings[inst].bits(),
|
||||||
@@ -62,8 +96,16 @@ fn recipe_ricmp<CS: CodeSink + ?Sized>(func: &Function, inst: Inst, sink: &mut C
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn recipe_rshamt<CS: CodeSink + ?Sized>(_func: &Function, _inst: Inst, _sink: &mut CS) {
|
fn recipe_rshamt<CS: CodeSink + ?Sized>(func: &Function, inst: Inst, sink: &mut CS) {
|
||||||
unimplemented!()
|
if let InstructionData::BinaryImm { arg, imm, .. } = func.dfg[inst] {
|
||||||
|
put_rshamt(func.encodings[inst].bits(),
|
||||||
|
func.locations[arg].unwrap_reg(),
|
||||||
|
imm.into(),
|
||||||
|
func.locations[func.dfg.first_result(inst)].unwrap_reg(),
|
||||||
|
sink);
|
||||||
|
} else {
|
||||||
|
panic!("Expected BinaryImm format: {:?}", func.dfg[inst]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// I-type instructions.
|
/// I-type instructions.
|
||||||
@@ -99,7 +141,7 @@ fn recipe_i<CS: CodeSink + ?Sized>(func: &Function, inst: Inst, sink: &mut CS) {
|
|||||||
func.locations[func.dfg.first_result(inst)].unwrap_reg(),
|
func.locations[func.dfg.first_result(inst)].unwrap_reg(),
|
||||||
sink);
|
sink);
|
||||||
} else {
|
} else {
|
||||||
panic!("Expected Binary format: {:?}", func.dfg[inst]);
|
panic!("Expected BinaryImm format: {:?}", func.dfg[inst]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user