Skip to content

Commit

Permalink
ghw: example loads
Browse files Browse the repository at this point in the history
  • Loading branch information
ekiwi committed Mar 5, 2024
1 parent 70c1b2c commit 76ad5fe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
7 changes: 6 additions & 1 deletion src/ghw/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,18 @@ pub struct GhwVecInfo {
max: GhwSignalId,
min: GhwSignalId,
two_state: bool,
signal_ref: SignalRef,
/// pointer to an alias list
alias: Option<NonZeroU32>,
}

impl GhwVecInfo {
pub fn new(min: GhwSignalId, max: GhwSignalId, two_state: bool) -> Self {
pub fn new(min: GhwSignalId, max: GhwSignalId, two_state: bool, signal_ref: SignalRef) -> Self {
Self {
min,
max,
two_state,
signal_ref,
alias: None,
}
}
Expand All @@ -317,6 +319,9 @@ impl GhwVecInfo {
pub fn max(&self) -> GhwSignalId {
self.max
}
pub fn signal_ref(&self) -> SignalRef {
self.signal_ref
}
pub fn alias(&self) -> Option<NonZeroU32> {
self.alias
}
Expand Down
4 changes: 2 additions & 2 deletions src/ghw/hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,14 +1052,14 @@ impl GhwSignals {

// create a new vec entry
let vec_id = self.vectors.len();
let id = self.new_signal_ref();
self.vectors
.push(GhwVecInfo::new(min_id, max_id, is_binary));
.push(GhwVecInfo::new(min_id, max_id, is_binary, id));
let tpe = if is_binary {
SignalType::TwoStateVec
} else {
SignalType::NineStateVec
};
let id = self.new_signal_ref();

// update all bits
for ii in min..=max {
Expand Down
12 changes: 7 additions & 5 deletions src/ghw/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use crate::ghw::common::*;
use crate::wavemem::{Encoder, States};
use crate::Hierarchy;
use crate::{Hierarchy, SignalRef};
use std::io::BufRead;

/// Reads the GHW signal values. `input` should be advanced until right after the end of hierarchy
Expand Down Expand Up @@ -133,8 +133,7 @@ fn read_cycle_signals(
/// This dispatches any remaining vector changes.
fn finish_time_step(vecs: &mut VecBuffer, enc: &mut Encoder) {
vecs.process_changed_signals(|signal_ref, data, states| {
todo!("finish timestep with vec_id! {signal_ref:?}");
// enc.raw_value_change(signal_ref, data, states);
enc.raw_value_change(signal_ref, data, states);
})
}

Expand Down Expand Up @@ -224,6 +223,7 @@ struct VecBufferInfo {
bit_change_start: u32,
bits: u32,
states: States,
signal_ref: SignalRef,
}

impl VecBufferInfo {
Expand Down Expand Up @@ -259,6 +259,7 @@ impl VecBuffer {
bit_change_start: bit_change_start as u32,
bits,
states,
signal_ref: vector.signal_ref(),
});
data_start += (bits as usize).div_ceil(states.bits_in_a_byte());
bit_change_start += (bits as usize).div_ceil(8);
Expand All @@ -278,13 +279,14 @@ impl VecBuffer {
}
}

fn process_changed_signals(&mut self, mut callback: impl FnMut(GhwVecId, &[u8], States)) {
fn process_changed_signals(&mut self, mut callback: impl FnMut(SignalRef, &[u8], States)) {
let change_list = std::mem::take(&mut self.change_list);
for vec_id in change_list.into_iter() {
if self.has_signal_changed(vec_id) {
let states = self.info[vec_id.index()].states;
let signal_ref = self.info[vec_id.index()].signal_ref;
let data = self.get_full_value_and_clear_changes(vec_id);
(callback)(vec_id, data, states);
(callback)(signal_ref, data, states);
}
}
}
Expand Down

0 comments on commit 76ad5fe

Please sign in to comment.