Repository navigation
feat(sim)!: make a tick one clock period and run every clock generator #1776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,8 +3,9 @@ use celox_testbench::{ | |
| AssertMessage as GenericAssertMessage, ClockCount as GenericClockCount, CompiledExpr, | ||
| ExecutableArgument, ExecutableAssertMessage, ExecutableClockCount, ExecutableLoopBound, | ||
| ExecutableStatement, ExecutableTestbench, ExprBytecode, LoopBound as GenericLoopBound, | ||
| SemanticArgument, SemanticComponentBinding, SemanticStatement, StateLocation, TestbenchProgram, | ||
| TestbenchSelection, TestbenchStatement as GenericTestbenchStatement, TestbenchTarget, | ||
| SemanticArgument, SemanticComponentBinding, SemanticStatement, StateLocation, TestbenchClock, | ||
| TestbenchProgram, TestbenchSelection, TestbenchStatement as GenericTestbenchStatement, | ||
| TestbenchTarget, | ||
| }; | ||
|
|
||
| use crate::{SignalRef, backend::SimBackend}; | ||
|
|
@@ -389,6 +390,17 @@ pub fn bind_testbench_program<B: SimBackend>( | |
| } | ||
| } | ||
| let random_seed = program.configured_random_seed(); | ||
| // A clock generator without an event drives no domain. | ||
| let clocks = program | ||
| .clocks() | ||
| .iter() | ||
| .filter_map(|clock| { | ||
| Some(TestbenchClock { | ||
| event: backend.resolve_event_opt(&clock.event)?, | ||
| period: clock.period, | ||
|
Comment on lines
+397
to
+400
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Dropping a generator when Useful? React with 👍 / 👎. |
||
| }) | ||
| }) | ||
| .collect(); | ||
| let components = program.components().to_vec(); | ||
| let component_libraries = program.component_libraries().to_vec(); | ||
| let component_file_base = program.component_file_base().map(ToOwned::to_owned); | ||
|
|
@@ -410,6 +422,7 @@ pub fn bind_testbench_program<B: SimBackend>( | |
| .collect(); | ||
| Some( | ||
| ExecutableTestbench::from_processes(processes, random_seed) | ||
| .with_clocks(clocks) | ||
| .with_private_signals(private_signals) | ||
| .with_component_runtime( | ||
| components, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -271,10 +271,21 @@ pub type SemanticStatement<A> = TestbenchStatement< | |
| pub type SemanticComponentBinding<A> = | ||
| ComponentBinding<A, SemanticSignal<A>, ExprBytecode<StateLocation<A>>>; | ||
|
|
||
| /// A `$tb::clock_gen` instance: a clock that runs from time 0, rising at | ||
| /// multiples of `period` and falling `ceil(period / 2)` after each rise, | ||
| /// whether or not a process waits on it. | ||
| #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] | ||
| pub struct TestbenchClock<Event> { | ||
| pub event: Event, | ||
| /// At least two. | ||
| pub period: u64, | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | ||
| pub struct TestbenchProgram<A> { | ||
| statements: Vec<SemanticStatement<A>>, | ||
| process_lengths: Vec<usize>, | ||
| clocks: Vec<TestbenchClock<A>>, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Adding Useful? React with 👍 / 👎. |
||
| private_variables: Vec<A>, | ||
| random_seed: Option<u64>, | ||
| components: Vec<TestbenchComponent>, | ||
|
|
@@ -288,6 +299,7 @@ impl<A> Default for TestbenchProgram<A> { | |
| Self { | ||
| statements: Vec::new(), | ||
| process_lengths: Vec::new(), | ||
| clocks: Vec::new(), | ||
| private_variables: Vec::new(), | ||
| random_seed: None, | ||
| components: Vec::new(), | ||
|
|
@@ -302,6 +314,7 @@ impl<A> TestbenchProgram<A> { | |
| pub fn new(statements: Vec<SemanticStatement<A>>) -> Self { | ||
| Self { | ||
| process_lengths: vec![statements.len()], | ||
| clocks: Vec::new(), | ||
| private_variables: Vec::new(), | ||
| statements, | ||
| random_seed: None, | ||
|
|
@@ -320,6 +333,16 @@ impl<A> TestbenchProgram<A> { | |
| program | ||
| } | ||
|
|
||
| /// The clock generators of the testbench. | ||
| pub fn with_clocks(mut self, clocks: Vec<TestbenchClock<A>>) -> Self { | ||
| self.clocks = clocks; | ||
| self | ||
| } | ||
|
|
||
| pub fn clocks(&self) -> &[TestbenchClock<A>] { | ||
| &self.clocks | ||
| } | ||
|
|
||
| /// Temporaries whose values belong to each independently suspended process. | ||
| pub fn with_private_variables(mut self, variables: Vec<A>) -> Self { | ||
| self.private_variables = variables; | ||
|
|
@@ -578,6 +601,7 @@ pub type ExecutableComponentBinding<Event, Signal> = ComponentBinding<Event, Sig | |
| pub struct ExecutableTestbench<Event, Signal> { | ||
| statements: Vec<ExecutableStatement<Event, Signal>>, | ||
| process_lengths: Vec<usize>, | ||
| clocks: Vec<TestbenchClock<Event>>, | ||
| private_signals: Vec<Signal>, | ||
| random_seed: Option<u64>, | ||
| components: Vec<TestbenchComponent>, | ||
|
|
@@ -597,6 +621,7 @@ impl<Event, Signal> ExecutableTestbench<Event, Signal> { | |
| ) -> Self { | ||
| Self { | ||
| process_lengths: vec![statements.len()], | ||
| clocks: Vec::new(), | ||
| private_signals: Vec::new(), | ||
| statements, | ||
| random_seed, | ||
|
|
@@ -633,6 +658,16 @@ impl<Event, Signal> ExecutableTestbench<Event, Signal> { | |
| program | ||
| } | ||
|
|
||
| /// The clock generators of the testbench. | ||
| pub fn with_clocks(mut self, clocks: Vec<TestbenchClock<Event>>) -> Self { | ||
| self.clocks = clocks; | ||
| self | ||
| } | ||
|
|
||
| pub fn clocks(&self) -> &[TestbenchClock<Event>] { | ||
| &self.clocks | ||
| } | ||
|
|
||
| pub fn with_private_signals(mut self, signals: Vec<Signal>) -> Self { | ||
| self.private_signals = signals; | ||
| self | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a clock generator belongs to a module with no
initialblock, it is excluded here becausesourceswas filtered byinitial_statements.is_some()above (and child sources without initial blocks may not be retained at all). If another process advances simulation time, that generator never entersExecutableTestbench::clocks, so its signal and clocked domains remain idle despite the new guarantee that every$tb::clock_genruns from time 0. Collect generators independently from the sources used to compile initial processes.Useful? React with 👍 / 👎.