Skip to content

Commit

Permalink
[difftest] support ordered memory write for scalar and vector
Browse files Browse the repository at this point in the history
  • Loading branch information
Clo91eaf committed Jul 16, 2024
1 parent c5d77f0 commit fa947f7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
4 changes: 4 additions & 0 deletions difftest/online_drive/dpi_c/dpi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,8 @@ void retire_vector_instruction(const svBitVecVal* retire) {
retire_vector_instruction_rs(dpi_call_target, retire);
}

void retire_vector_memory(const svBitVecVal* retire) {
retire_vector_memory_rs(dpi_call_target);
}

} // extern "C"
8 changes: 7 additions & 1 deletion difftest/online_drive/dpi_c/dpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ extern void issue_vector_instruction_rs(
svBitVecVal *issue);

extern void retire_vector_instruction_rs(
/// struct issue_data {
/// struct retire_data {
/// uint32_t rd;
/// uint32_t data;
/// uint32_t writeRd;
Expand All @@ -86,6 +86,12 @@ extern void retire_vector_instruction_rs(
void *dpi_call_target,
const svBitVecVal *retire);

extern void retire_vector_memory_rs(
/// struct retire_data {
/// bool dummy;
/// }
void *dpi_call_target);

#ifdef __cplusplus
}
#endif
6 changes: 6 additions & 0 deletions difftest/online_drive/src/dpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ unsafe extern "C" fn retire_vector_instruction_rs(target: *mut (), retire_src: *
driver.retire_instruction(retire)
}

#[no_mangle]
unsafe extern "C" fn retire_vector_memory_rs(target: *mut (), retire_src: *const SvBitVecVal) {
let driver = &mut *(target as *mut Driver);
driver.retire_memory();
}

//--------------------------------
// import functions and wrappers
//--------------------------------
Expand Down
18 changes: 17 additions & 1 deletion difftest/online_drive/src/drive.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use common::spike_runner::SpikeRunner;
use common::MEM_SIZE;
use spike_rs::clip;
use spike_rs::spike_event::MemAccessRecord;
use spike_rs::spike_event::SpikeEventType;
use spike_rs::util::load_elf_to_buffer;
Expand Down Expand Up @@ -27,6 +28,7 @@ pub(crate) struct Driver {
// driver state
last_commit_cycle: u64,
issued: u64,
vector_lsu_count: u8,

shadow_mem: Vec<u8>,
}
Expand Down Expand Up @@ -85,6 +87,7 @@ impl Driver {
last_commit_cycle: 0,

issued: 0,
vector_lsu_count: 0,
shadow_mem: vec![0; MEM_SIZE],
};
self_.spike_runner.load_elf(&args.common_args.elf_file).unwrap();
Expand Down Expand Up @@ -292,6 +295,15 @@ impl Driver {
se.inst_bits
);
self.issued += 1;

// if the instruction is a vector store/load, increment the vector_lsu_count
let opcode = clip(se.inst_bits, 0, 6);
let width = clip(se.inst_bits, 12, 14);
if (opcode == 0b0100111 /* store */ || opcode == 0b0000111/* load */)
&& (width.wrapping_sub(1) & 0b100 != 0)
{
self.vector_lsu_count += 1;
}
// not a fence, issue it
IssueData {
instruction_bits: se.inst_bits,
Expand All @@ -301,7 +313,7 @@ impl Driver {
vl: se.vl,
vstart: se.vstart as u32,
vcsr: se.vcsr(),
meta: ISSUE_VALID,
meta: self.vector_lsu_count == 0,
}
}
}
Expand All @@ -324,4 +336,8 @@ impl Driver {
self.spike_runner.commit_queue.pop_back();
self.last_commit_cycle = get_t();
}

pub(crate) fn retire_memory(&mut self) {
self.vector_lsu_count -= 1;
}
}

0 comments on commit fa947f7

Please sign in to comment.