Skip to content

Commit

Permalink
back.pysim: redesign the simulator.
Browse files Browse the repository at this point in the history
The redesign introduces no fundamental incompatibilities, but it does
involve minor breaking changes:
  * The simulator commands were moved from hdl.ast to back.pysim
    (instead of only being reexported from back.pysim).
  * back.pysim.DeadlineError was removed.

Summary of changes:
  * The new simulator compiles HDL to Python code and is >6x faster.
    (The old one compiled HDL to lots of Python lambdas.)
  * The new simulator is a straightforward, rigorous implementation
    of the Synchronous Reactive Programming paradigm, instead of
    a pile of ad-hoc code with no particular design driving it.
  * The new simulator never raises DeadlineError, and there is no
    limit on the amount of delta cycles.
  * The new simulator robustly handles multiclock designs.
  * The new simulator can be reset, such that the compiled design
    can be reused, which can save significant runtime with large
    designs.
  * Generators can no longer be added as processes, since that would
    break reset(); only generator functions may be. If necessary,
    they may be added by wrapping them into a generator function;
    a deprecated fallback does just that. This workaround will raise
    an exception if the simulator is reset and restarted.
  * The new simulator does not depend on Python extensions.
    (The old one required bitarray, which did not provide wheels.)

Fixes amaranth-lang#28.
Fixes amaranth-lang#34.
Fixes amaranth-lang#160.
Fixes amaranth-lang#161.
Fixes amaranth-lang#215.
Fixes amaranth-lang#242.
Fixes #262.
  • Loading branch information
whitequark committed Nov 28, 2019
1 parent f8428ff commit 7df7005
Show file tree
Hide file tree
Showing 7 changed files with 1,170 additions and 912 deletions.
24 changes: 11 additions & 13 deletions examples/basic/ctr_en.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ def elaborate(self, platform):

print(verilog.convert(ctr, ports=[ctr.o, ctr.en]))

with pysim.Simulator(ctr,
vcd_file=open("ctrl.vcd", "w"),
gtkw_file=open("ctrl.gtkw", "w"),
traces=[ctr.en, ctr.v, ctr.o]) as sim:
sim.add_clock(1e-6)
def ce_proc():
yield; yield; yield
yield ctr.en.eq(1)
yield; yield; yield
yield ctr.en.eq(0)
yield; yield; yield
yield ctr.en.eq(1)
sim.add_sync_process(ce_proc())
sim = pysim.Simulator(ctr)
sim.add_clock(1e-6)
def ce_proc():
yield; yield; yield
yield ctr.en.eq(1)
yield; yield; yield
yield ctr.en.eq(0)
yield; yield; yield
yield ctr.en.eq(1)
sim.add_sync_process(ce_proc)
with sim.write_vcd("ctrl.vcd", "ctrl.gtkw", traces=[ctr.en, ctr.v, ctr.o]):
sim.run_until(100e-6, run_passive=True)
Loading

0 comments on commit 7df7005

Please sign in to comment.