From 0a020d37dc66484ce1c879379fb988c5bf4afff4 Mon Sep 17 00:00:00 2001 From: tignear Date: Wed, 28 Oct 2026 22:32:36 +0900 Subject: [PATCH] perf(vpi): snapshot pending deposits once per edge batch Queued writes cloned the full deposit map into the open clock-edge batch after every input write. Keep that batch attached to the current deposits and freeze its map once before a member transitions again or before replay. Closed batches retain their own per-edge values and callback overrides keep the existing replay behavior. This avoids repeated full-map and BigUint copies while collecting simultaneous input writes. Extend the queued-edge regression stimulus with overwritten data deposits before and after clock transitions. Validation: focused edge-value regression, all 68 VPI unit/API tests, all 10 ignored cocotb integrations, all-target clippy with warnings denied, and workspace formatting. Change-Id: I2a51a4eca0ff3f094e20b289f003f23344612ea6 --- crates/celox-vpi/src/lib.rs | 22 ++++++++++++++++------ crates/celox-vpi/tests/basic_vpi.rs | 4 ++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/crates/celox-vpi/src/lib.rs b/crates/celox-vpi/src/lib.rs index 4ec79997709..ada92725bbd 100644 --- a/crates/celox-vpi/src/lib.rs +++ b/crates/celox-vpi/src/lib.rs @@ -529,6 +529,16 @@ struct PendingWrites { settle: bool, } +impl PendingWrites { + // An open batch follows the current deposits. Freeze its map only when a + // member transitions again or before replay, rather than after every write. + fn close_edge_batch(&mut self) { + if let Some(index) = self.open_edge_batch.take() { + self.edge_batches[index].deposits = self.deposits.clone(); + } + } +} + struct PendingEdgeBatch { active_signals: Vec, transition_signals: Vec, @@ -598,7 +608,7 @@ fn record_pending_write( }); if open_contains_signal && event_transition { - pending.open_edge_batch = None; + pending.close_edge_batch(); } pending @@ -612,17 +622,14 @@ fn record_pending_write( if active { pending.edge_batches[index].active_signals.push(identity); } - pending.edge_batches[index].deposits = pending.deposits.clone(); } else { pending.edge_batches.push(PendingEdgeBatch { active_signals: active.then_some(identity).into_iter().collect(), transition_signals: vec![identity], - deposits: pending.deposits.clone(), + deposits: HashMap::default(), }); pending.open_edge_batch = Some(pending.edge_batches.len() - 1); } - } else if let Some(index) = pending.open_edge_batch { - pending.edge_batches[index].deposits = pending.deposits.clone(); } pending.settle = true; } @@ -2021,7 +2028,10 @@ fn flush_inertial_writes_for_host(host: &VpiHost) -> bool { } fn flush_pending_writes_for_host(host: &VpiHost) -> bool { - let pending = borrow_cell_mut(&host.pending_writes, std::mem::take); + let pending = borrow_cell_mut(&host.pending_writes, |pending| { + pending.close_edge_batch(); + std::mem::take(pending) + }); if !pending.settle { return true; } diff --git a/crates/celox-vpi/tests/basic_vpi.rs b/crates/celox-vpi/tests/basic_vpi.rs index 4f64341ea6e..64b2056b795 100644 --- a/crates/celox-vpi/tests/basic_vpi.rs +++ b/crates/celox-vpi/tests/basic_vpi.rs @@ -2474,10 +2474,14 @@ unsafe extern "C" fn drive_two_edges_with_distinct_data(data: *mut VpiCbData) -> let d = EDGE_DATA_HANDLE.load(Ordering::SeqCst) as VpiHandle; unsafe { put_int(clk, 1); + put_int(d, 7); put_int(d, 1); put_int(clk, 0); + put_int(d, 9); put_int(d, 2); put_int(clk, 1); + put_int(d, 8); + put_int(d, 2); } 0 }