Zero-cycle JUMP
This commit is contained in:
@@ -27,7 +27,8 @@ fn init_logger() {
|
||||
env_logger::init();
|
||||
}
|
||||
|
||||
const COLUMN_BIT_OFFSET: usize = 10;
|
||||
const GRF_A_BIT_OFFSET: usize = 10;
|
||||
const GRF_B_BIT_OFFSET: usize = 13;
|
||||
const BURST_LENGTH: usize = 32;
|
||||
|
||||
const GRF_NUM_REGISTERS: usize = 8;
|
||||
@@ -111,15 +112,35 @@ impl PimVM {
|
||||
|
||||
let pim_unit = &mut self.pim_units[bank_index as usize];
|
||||
|
||||
let current_pc = pim_unit.pc;
|
||||
let mut inst = self.pim_config.kernel.0[pim_unit.pc as usize];
|
||||
pim_unit.pc += 1;
|
||||
|
||||
let inst = self.pim_config.kernel.0[current_pc as usize];
|
||||
let aam_grf_a_index = (address >> GRF_A_BIT_OFFSET) & 0b111;
|
||||
let aam_grf_b_index = (address >> GRF_B_BIT_OFFSET) & 0b111;
|
||||
|
||||
let aam_grf_a_index = (address >> COLUMN_BIT_OFFSET) & 0b111;
|
||||
let aam_grf_b_index = (address >> COLUMN_BIT_OFFSET + 3) & 0b111;
|
||||
log::debug!("PimUnit {bank_index} Execute PC {}: {inst:?}", pim_unit.pc);
|
||||
|
||||
log::debug!("PimUnit {bank_index} Execute PC {current_pc}: {inst:?}");
|
||||
// The JUMP instruction is zero-cycle and not actually executed
|
||||
while let Instruction::JUMP { offset, count } = inst {
|
||||
pim_unit.jump_counter = match pim_unit.jump_counter {
|
||||
Some(jump_counter) => jump_counter.checked_sub(1),
|
||||
None => count.checked_sub(1),
|
||||
};
|
||||
|
||||
if pim_unit.jump_counter != None {
|
||||
let new_pc = pim_unit.pc as i32 + offset as i32;
|
||||
|
||||
if new_pc < 0 || new_pc >= 32 {
|
||||
panic!("Invalid PC {new_pc} after JUMP: {inst:?}");
|
||||
}
|
||||
|
||||
pim_unit.pc = new_pc as _;
|
||||
log::debug!("PimUnit {bank_index} New PC {new_pc}: {inst:?}");
|
||||
}
|
||||
|
||||
inst = self.pim_config.kernel.0[pim_unit.pc as usize];
|
||||
pim_unit.pc += 1;
|
||||
}
|
||||
|
||||
match inst {
|
||||
Instruction::NOP => (),
|
||||
@@ -127,23 +148,7 @@ impl PimVM {
|
||||
pim_unit.jump_counter = None;
|
||||
pim_unit.pc = 0;
|
||||
}
|
||||
Instruction::JUMP { offset, count } => {
|
||||
pim_unit.jump_counter = match pim_unit.jump_counter {
|
||||
Some(jump_counter) => jump_counter.checked_sub(1),
|
||||
None => count.checked_sub(1),
|
||||
};
|
||||
|
||||
if pim_unit.jump_counter != None {
|
||||
let new_pc = current_pc as i32 + offset as i32;
|
||||
|
||||
if new_pc < 0 || new_pc >= 32 {
|
||||
panic!("Invalid PC {new_pc} after JUMP: {inst:?}");
|
||||
}
|
||||
|
||||
pim_unit.pc = new_pc as _;
|
||||
log::debug!("PimUnit {bank_index} New PC {new_pc}: {inst:?}");
|
||||
}
|
||||
}
|
||||
Instruction::JUMP { .. } => unreachable!(),
|
||||
Instruction::MOV { src, dst } | Instruction::FILL { src, dst } => {
|
||||
let data = PimVM::load(src, pim_unit, &bank_data);
|
||||
PimVM::store(dst, pim_unit, &data);
|
||||
@@ -284,7 +289,7 @@ impl PimVM {
|
||||
.try_into()
|
||||
.unwrap();
|
||||
|
||||
log::debug!("{data0:#?}\n{data1:#?}\n{data2:#?}\n{product:#?}\n{sum:#?}");
|
||||
log::debug!("{data0:?}\n{data1:?}\n{data2:?}\n{product:?}\n{sum:?}");
|
||||
PimVM::store(dst, pim_unit, &sum);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user