From 8402abbeda390c6107e3aa14fbb7ac6bf6849cdd Mon Sep 17 00:00:00 2001 From: Clo91eaf Date: Thu, 22 Aug 2024 09:57:20 +0800 Subject: [PATCH] [t1rocket] fix wrong payload logic in axi_load_store --- t1rocketemu/online_dpi/src/dpi.rs | 25 ++++++++++++------------- t1rocketemu/perf.txt | 1 + 2 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 t1rocketemu/perf.txt diff --git a/t1rocketemu/online_dpi/src/dpi.rs b/t1rocketemu/online_dpi/src/dpi.rs index 632c96a30..c04be5348 100644 --- a/t1rocketemu/online_dpi/src/dpi.rs +++ b/t1rocketemu/online_dpi/src/dpi.rs @@ -37,26 +37,27 @@ unsafe fn fill_axi_read_payload(dst: *mut SvBitVecVal, dlen: u32, payload: &AxiR unsafe fn load_from_payload( payload: &*const SvBitVecVal, data_width: usize, - dlen: usize, + size: usize, ) -> (Vec, &[u8]) { let src = *payload as *mut u8; - let data_width_in_byte = dlen / 8; - let strb_width_in_byte = dlen / data_width; + let data_width_in_byte = size; + let strb_width_per_byte = if data_width < 64 { 4 } else { 8 }; + let strb_width_in_byte = size / strb_width_per_byte; + let payload_size_in_byte = strb_width_in_byte + data_width_in_byte; // data width in byte let byte_vec = std::slice::from_raw_parts(src, payload_size_in_byte); let strobe = &byte_vec[0..strb_width_in_byte]; let data = &byte_vec[strb_width_in_byte..]; - let strb_width_in_bit = data_width / 8; let masks: Vec = strobe .into_iter() .flat_map(|strb| { - let mask: Vec = (0..strb_width_in_bit).map(|i| (strb & (1 << i)) != 0).collect(); + let mask: Vec = (0..strb_width_per_byte).map(|i| (strb & (1 << i)) != 0).collect(); mask }) .collect(); - assert!( - masks.len() == data.len(), + assert_eq!( + masks.len(), data.len(), "strobe bit width is not aligned with data byte width" ); @@ -99,8 +100,7 @@ unsafe extern "C" fn axi_write_highBandwidthAXI( ); let mut driver = DPI_TARGET.lock().unwrap(); let driver = driver.as_mut().unwrap(); - let data_width = 32; // TODO: get from driver - let (strobe, data) = load_from_payload(&payload, 32, driver.dlen as usize); + let (strobe, data) = load_from_payload(&payload, driver.dlen as usize, (1 << awsize) as usize); driver.axi_write_high_bandwidth(awaddr as u32, awsize as u64, &strobe, data); } @@ -156,8 +156,7 @@ unsafe extern "C" fn axi_write_highOutstandingAXI( ); let mut driver = DPI_TARGET.lock().unwrap(); let driver = driver.as_mut().unwrap(); - let data_width = 32; // TODO: get from driver - let (strobe, data) = load_from_payload(&payload, data_width, 32); + let (strobe, data) = load_from_payload(&payload, 32, (1 << awsize) as usize); driver.axi_write_high_outstanding(awaddr as u32, awsize as u64, &strobe, data); } @@ -211,8 +210,8 @@ unsafe extern "C" fn axi_write_loadStoreAXI( ); let mut driver = DPI_TARGET.lock().unwrap(); let driver = driver.as_mut().unwrap(); - let data_width = 32; // TODO: get from sim - let (strobe, data) = load_from_payload(&payload, data_width, driver.dlen as usize); + let data_width = if awsize <= 2 { 32 } else { 8 * (1 << awsize) } as usize; + let (strobe, data) = load_from_payload(&payload, data_width, (driver.dlen / 8) as usize); driver.axi_write_load_store(awaddr as u32, awsize as u64, &strobe, data); } diff --git a/t1rocketemu/perf.txt b/t1rocketemu/perf.txt new file mode 100644 index 000000000..7ad90e47e --- /dev/null +++ b/t1rocketemu/perf.txt @@ -0,0 +1 @@ +total_cycles: 516110 \ No newline at end of file