Emit I-type instructions for RISC-V.
These are the BinaryImm formats.
This commit is contained in:
@@ -39,5 +39,25 @@ ebb0:
|
|||||||
[-,%x7] v44 = icmp ult, v1, v2 ; bin: 015533b3
|
[-,%x7] v44 = icmp ult, v1, v2 ; bin: 015533b3
|
||||||
[-,%x16] v45 = icmp ult, v2, v1 ; bin: 00aab833
|
[-,%x16] v45 = icmp ult, v2, v1 ; bin: 00aab833
|
||||||
|
|
||||||
|
; Integer Register-Immediate Instructions
|
||||||
|
|
||||||
|
; addi
|
||||||
|
[-,%x7] v100 = iadd_imm v1, 1000 ; bin: 3e850393
|
||||||
|
[-,%x16] v101 = iadd_imm v2, -905 ; bin: c77a8813
|
||||||
|
; TBD: slti
|
||||||
|
; andi
|
||||||
|
[-,%x7] v110 = band_imm v1, 1000 ; bin: 3e857393
|
||||||
|
[-,%x16] v111 = band_imm v2, -905 ; bin: c77af813
|
||||||
|
; ori
|
||||||
|
[-,%x7] v112 = bor_imm v1, 1000 ; bin: 3e856393
|
||||||
|
[-,%x16] v113 = bor_imm v2, -905 ; bin: c77ae813
|
||||||
|
; xori
|
||||||
|
[-,%x7] v114 = bxor_imm v1, 1000 ; bin: 3e854393
|
||||||
|
[-,%x16] v115 = bxor_imm v2, -905 ; bin: c77ac813
|
||||||
|
|
||||||
|
; TBD: slli
|
||||||
|
; TBD: srli
|
||||||
|
; TBD: srai
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,8 +66,41 @@ fn recipe_rshamt<CS: CodeSink + ?Sized>(_func: &Function, _inst: Inst, _sink: &m
|
|||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn recipe_i<CS: CodeSink + ?Sized>(_func: &Function, _inst: Inst, _sink: &mut CS) {
|
/// I-type instructions.
|
||||||
unimplemented!()
|
///
|
||||||
|
/// 31 19 14 11 6
|
||||||
|
/// imm rs1 funct3 rd opcode
|
||||||
|
/// 20 15 12 7 0
|
||||||
|
///
|
||||||
|
/// Encoding bits: `opcode[6:2] | (funct3 << 5)`
|
||||||
|
fn put_i<CS: CodeSink + ?Sized>(bits: u16, rs1: RegUnit, imm: i64, rd: RegUnit, sink: &mut CS) {
|
||||||
|
let bits = bits as u32;
|
||||||
|
let opcode5 = bits & 0x1f;
|
||||||
|
let funct3 = (bits >> 5) & 0x7;
|
||||||
|
let rs1 = rs1 as u32 & 0x1f;
|
||||||
|
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 |= (imm << 20) as u32;
|
||||||
|
|
||||||
|
sink.put4(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn recipe_i<CS: CodeSink + ?Sized>(func: &Function, inst: Inst, sink: &mut CS) {
|
||||||
|
if let InstructionData::BinaryImm { arg, imm, .. } = func.dfg[inst] {
|
||||||
|
put_i(func.encodings[inst].bits(),
|
||||||
|
func.locations[arg].unwrap_reg(),
|
||||||
|
imm.into(),
|
||||||
|
func.locations[func.dfg.first_result(inst)].unwrap_reg(),
|
||||||
|
sink);
|
||||||
|
} else {
|
||||||
|
panic!("Expected Binary format: {:?}", func.dfg[inst]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn recipe_iret<CS: CodeSink + ?Sized>(_func: &Function, _inst: Inst, _sink: &mut CS) {
|
fn recipe_iret<CS: CodeSink + ?Sized>(_func: &Function, _inst: Inst, _sink: &mut CS) {
|
||||||
|
|||||||
Reference in New Issue
Block a user