diff --git a/difftest/t1-simulator/Cargo.lock b/difftest/t1-simulator/Cargo.lock
index d242b3a3d9..3ca2112f12 100644
--- a/difftest/t1-simulator/Cargo.lock
+++ b/difftest/t1-simulator/Cargo.lock
@@ -65,6 +65,12 @@ version = "1.0.80"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ad32ce52e4161730f7098c077cd2ed6229b5804ccf99e5366be1ab72a98b4e1"
+[[package]]
+name = "autocfg"
+version = "1.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
+
[[package]]
name = "cfg-if"
version = "1.0.0"
@@ -182,6 +188,34 @@ dependencies = [
"winapi",
]
+[[package]]
+name = "num-bigint"
+version = "0.4.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9"
+dependencies = [
+ "num-integer",
+ "num-traits",
+]
+
+[[package]]
+name = "num-integer"
+version = "0.1.46"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
+dependencies = [
+ "num-traits",
+]
+
+[[package]]
+name = "num-traits"
+version = "0.2.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
+dependencies = [
+ "autocfg",
+]
+
[[package]]
name = "once_cell"
version = "1.19.0"
@@ -340,6 +374,7 @@ dependencies = [
"lazy_static",
"libc",
"libloading",
+ "num-bigint",
"serde",
"serde_json",
"tracing",
diff --git a/difftest/t1-simulator/Cargo.toml b/difftest/t1-simulator/Cargo.toml
index b49da3e135..855f24dd9d 100644
--- a/difftest/t1-simulator/Cargo.toml
+++ b/difftest/t1-simulator/Cargo.toml
@@ -16,4 +16,5 @@ anyhow = "1.0.79"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
lazy_static = "1.4.0"
+num-bigint = "0.4.6"
diff --git a/difftest/t1-simulator/src/difftest.rs b/difftest/t1-simulator/src/difftest.rs
index 6c19be573d..da3b2ce41e 100644
--- a/difftest/t1-simulator/src/difftest.rs
+++ b/difftest/t1-simulator/src/difftest.rs
@@ -82,88 +82,120 @@ impl Difftest {
let event = self.dut.step()?;
+ let cycle = event.parameter.cycle.unwrap();
+ self.spike.cycle = cycle;
match &*event.event {
- "peekTL" => {}
+ "memoryWrite" => {
+ let data = event.parameter.data.clone().unwrap();
+ let mask = event.parameter.mask.clone().unwrap();
+ let address = event.parameter.address.unwrap();
+ let source = event.parameter.source.unwrap();
+ self.spike.peek_memory_write(MemoryWriteEvent {
+ mask,
+ data,
+ source,
+ address,
+ cycle,
+ })
+ }
"issue" => {
let idx = event.parameter.idx.unwrap();
- let cycle = event.parameter.cycle.unwrap();
- self.spike.cycle = cycle;
- self.peek_issue(IssueEvent { idx, cycle }).unwrap();
+ self.peek_issue(IssueEvent { idx, cycle })
}
"lsuEnq" => {
let enq = event.parameter.enq.unwrap();
- let cycle = event.parameter.cycle.unwrap();
- self.spike.cycle = cycle;
- self.update_lsu_idx(LsuEnqEvent { enq, cycle }).unwrap();
+ self.update_lsu_idx(LsuEnqEvent { enq, cycle })
}
"vrfWriteFromLsu" => {
let idx = event.parameter.idx.unwrap();
let vd = event.parameter.vd.unwrap();
let offset = event.parameter.offset.unwrap();
- let mask = event.parameter.mask.unwrap();
- let data = event.parameter.data.unwrap();
+ let mask = event.parameter.mask.clone().unwrap();
+ let data = event.parameter.data.clone().unwrap();
let instruction = event.parameter.instruction.unwrap();
let lane = event.parameter.lane.unwrap();
- let cycle = event.parameter.cycle.unwrap();
- self.spike.cycle = cycle;
assert!(idx < self.spike.config.dlen / 32);
- self
- .spike
- .peek_vrf_write_from_lsu(VrfWriteEvent {
- idx: lane.trailing_zeros(),
- vd,
- offset,
- mask,
- data,
- instruction,
- cycle,
- })
- .unwrap();
+ assert!(data.len() <= 4, "data length should be less than 4");
+ let mut data_array = [0u8; 4];
+ data
+ .iter()
+ .enumerate()
+ .for_each(|(i, &byte)| data_array[i] = byte);
+ let data = u32::from_le_bytes(data_array);
+ // convert mask to u8
+ let mask = mask
+ .iter()
+ .rev()
+ .fold(0, |acc, &bit| (acc << 1) | bit as u8);
+
+ self.spike.peek_vrf_write_from_lsu(VrfWriteEvent {
+ idx: lane.trailing_zeros(),
+ vd,
+ offset,
+ mask,
+ data,
+ instruction,
+ cycle,
+ })
}
"vrfWriteFromLane" => {
let idx = event.parameter.idx.unwrap();
let vd = event.parameter.vd.unwrap();
let offset = event.parameter.offset.unwrap();
- let mask = event.parameter.mask.unwrap();
- let data = event.parameter.data.unwrap();
+ let mask = event.parameter.mask.clone().unwrap();
+ let data = event.parameter.data.clone().unwrap();
let instruction = event.parameter.instruction.unwrap();
- let cycle = event.parameter.cycle.unwrap();
- self.spike.cycle = cycle;
assert!(idx < self.spike.config.dlen / 32);
- self
- .spike
- .peek_vrf_write_from_lane(VrfWriteEvent {
- idx,
- vd,
- offset,
- mask,
- data,
- instruction,
- cycle,
- })
- .unwrap();
+
+ assert!(data.len() <= 4, "data length should be less than 4");
+ let mut array = [0u8; 4];
+ data
+ .iter()
+ .enumerate()
+ .for_each(|(i, &byte)| array[i] = byte);
+ let data = u32::from_le_bytes(array);
+ // convert mask to u8
+ let mask = mask
+ .iter()
+ .rev()
+ .fold(0, |acc, &bit| (acc << 1) | bit as u8);
+
+ self.spike.peek_vrf_write_from_lane(VrfWriteEvent {
+ idx,
+ vd,
+ offset,
+ mask,
+ data,
+ instruction,
+ cycle,
+ })
}
"inst" => {
- let data = event.parameter.data.unwrap() as u32;
- let cycle = event.parameter.cycle.unwrap();
- self.spike.cycle = cycle;
+ let data = event.parameter.data.clone().unwrap();
// let vxsat = event.parameter.vxsat.unwrap();
// let rd_valid = event.parameter.rd_valid.unwrap();
// let rd = event.parameter.rd.unwrap();
// let mem = event.parameter.mem.unwrap();
+ assert!(data.len() <= 4, "data length should be less than 4");
+ let mut array = [0u8; 4];
+ data
+ .iter()
+ .enumerate()
+ .for_each(|(i, &byte)| array[i] = byte);
+ let data = u32::from_le_bytes(array);
+
let se = self.spike.to_rtl_queue.back().unwrap();
se.record_rd_write(data).unwrap();
se.check_is_ready_for_commit(cycle).unwrap();
self.spike.to_rtl_queue.pop_back();
+ Ok(())
}
_ => {
panic!("unknown event: {}", event.event)
}
}
-
- Ok(())
}
}
diff --git a/difftest/t1-simulator/src/difftest/dut.rs b/difftest/t1-simulator/src/difftest/dut.rs
index 51cb86fa16..cf2b8593c3 100644
--- a/difftest/t1-simulator/src/difftest/dut.rs
+++ b/difftest/t1-simulator/src/difftest/dut.rs
@@ -1,14 +1,43 @@
-use serde::Deserialize;
+use num_bigint::BigUint;
+use serde::{Deserialize, Deserializer};
use std::io::BufRead;
use std::path::Path;
+use std::str::FromStr;
-#[derive(Deserialize, Debug, PartialEq, Clone)]
-pub enum Opcode {
- PutFullData = 0,
- PutPartialData = 1,
- Get = 4,
- // AccessAckData = 0,
- // AccessAck = 0,
+fn bigint_to_vec_u8<'de, D>(deserializer: D) -> Result