Implement SLLI and fix sign extension of immediates for I-type and S-type instructions
This commit is contained in:
@@ -52,12 +52,12 @@ impl Instruction {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn imm_i(self) -> DWord {
|
pub fn imm_i(self) -> DWord {
|
||||||
(self.0 as i64 >> 20) as DWord
|
(self.0 as i32 as i64 >> 20) as DWord
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn imm_s(self) -> DWord {
|
pub fn imm_s(self) -> DWord {
|
||||||
(self.0 as i64 >> (25 - 5) & (0x7f << 5)) as DWord | (self.0 >> 7 & 0b1111) as DWord
|
(self.0 as i32 as i64 >> (25 - 5) & (0x7f << 5)) as DWord | (self.0 >> 7 & 0b1111) as DWord
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -88,12 +88,12 @@ impl Instruction {
|
|||||||
// The following are AFAIK only used for shift by immediate operations
|
// The following are AFAIK only used for shift by immediate operations
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn funct6(self) -> u8 {
|
pub fn funct6(self) -> u8 {
|
||||||
(self.0 >> 26 & 0x3f) as u8
|
(self.0 >> 26 & 0x3f) as u8
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn imm_shamt(self) -> usize {
|
pub fn imm_shamt(self) -> usize {
|
||||||
(self.0 >> 20 & 0x3f) as usize
|
(self.0 >> 20 & 0x3f) as usize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ pub(crate) fn find_and_exec(instr: Instruction, core: &mut Core) -> Option<Instr
|
|||||||
0b00100 => match instr.funct3() {
|
0b00100 => match instr.funct3() {
|
||||||
// OP_IMM
|
// OP_IMM
|
||||||
0b000 => Some(rvi::addi(core, instr)),
|
0b000 => Some(rvi::addi(core, instr)),
|
||||||
|
0b001 => match instr.funct6() {
|
||||||
|
// left-shift immediate
|
||||||
|
0b000000 => Some(rvi::slli(core, instr)),
|
||||||
|
_ => None,
|
||||||
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
0b00110 => match instr.funct3() {
|
0b00110 => match instr.funct3() {
|
||||||
|
|||||||
@@ -64,3 +64,18 @@ pub fn jal(core: &mut Core, instr: Instruction) -> InstructionResult {
|
|||||||
core.pc = core.pc.wrapping_add(instr.imm_j());
|
core.pc = core.pc.wrapping_add(instr.imm_j());
|
||||||
InstructionResult::Normal
|
InstructionResult::Normal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn slli(core: &mut Core, instr: Instruction) -> InstructionResult {
|
||||||
|
core.reg_write(instr.rd(), core.reg_read(instr.rs1()) << instr.imm_shamt());
|
||||||
|
|
||||||
|
eprintln!(
|
||||||
|
"slli x{}, x{}, {}",
|
||||||
|
instr.rd(),
|
||||||
|
instr.rs1(),
|
||||||
|
instr.imm_shamt()
|
||||||
|
);
|
||||||
|
|
||||||
|
core.pc = core.pc.wrapping_add(4);
|
||||||
|
|
||||||
|
InstructionResult::Normal
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user