Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions crates/celox-vpi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<VpiSignalIdentity>,
transition_signals: Vec<VpiSignalIdentity>,
Expand Down Expand Up @@ -598,7 +608,7 @@ fn record_pending_write(
});

if open_contains_signal && event_transition {
pending.open_edge_batch = None;
pending.close_edge_batch();
}

pending
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions crates/celox-vpi/tests/basic_vpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading