Commit graph

287 commits

Author SHA1 Message Date
whitequark e88d283ed3 hdl.ast: simplify Mux implementation. 2021-10-02 14:18:02 +00:00
Robin Ole Heinemann 25caf4045b *: remove unused imports 2021-05-18 20:18:55 +00:00
whitequark 4e7e0b33d5 back.rtlil: give private items an appropriate name. NFCI. 2020-12-12 12:20:49 +00:00
whitequark 87454b0b6f back.{verilog,rtlil}: adjust $verilog_initial_trigger insertion.
To track upstream changes.
2020-10-25 01:59:46 +00:00
whitequark 955f3f6dcc back.verilog: use proc -nomux if it is available.
Yosys offers no stability guarantees for individual `proc_*` passes,
though so far it worked out fine. This commit changes the Verilog
backend to use `proc -nomux` instead, which is guaranteed to have
backwards-compatible behavior.

Fixes #479.
2020-08-27 13:03:15 +00:00
whitequark b65e11f38f sim: split into base, core, and engines.
Before this commit, each simulation engine (which is only pysim at
the moment, but also cxxsim soon) was a subclass of SimulatorCore,
and every simulation engine module would essentially duplicate
the complete structure of a simulator, with code partially shared.

This was a really bad idea: it was inconvenient to use, with
downstream code having to branch between e.g. PySettle and CxxSettle;
it had no well-defined external interface; it had multiple virtually
identical entry points; and it had no separation between simulation
algorithms and glue code.

This commit completely rearranges simulation code.
  1. sim._base defines internal simulation interfaces. The clarity of
     these internal interfaces is important because simulation
     engines mix and match components to provide a consistent API
     regardless of the chosen engine.
  2. sim.core defines the external simulation interface: the commands
     and the simulator facade. The facade provides a single entry
     point and, when possible, validates or lowers user input.
     It also imports built-in simulation engines by their symbolic
     name, avoiding eager imports of pyvcd or ctypes.
  3. sim.xxxsim (currently, only sim.pysim) defines the simulator
     implementation: time and state management, process scheduling,
     and waveform dumping.

The new simulator structure has none of the downsides of the old one.

See #324.
2020-08-27 11:52:31 +00:00
whitequark 07a3685da8 back.rtlil: do not squash empty modules.
In commit 9faa1d37, the RTLIL backend was changed to ignore modules
without ports completely, since Yosys would recognize empty modules
as black boxes without explicit `write_verilog -noblackbox` and break
the design. That change had many flaws:
  * It removed instances without ports, which are used in e.g. SoC
    FPGAs to instantiate a dummy CPU.
  * It removed fragments without ports, which can appear in e.g. SoC
    FPGAs in case the fabric is not connected to any I/O ports.
  * Finally, it was just conceptually unjustified.

This commit changes the logic to actually check for empty fragments,
and instead of removing them, it adds a dummy wire inside. It would
be possible to use the Yosys-specific (*noblackbox*) attribute.
However, it would be necessary to strip it for most targets right
away, and also the wire doubles as documentation.

Fixes #441.
2020-08-26 22:45:19 +00:00
whitequark 12beda6e5b back.verilog: omit Verilog initial trigger only if Yosys adds it.
Verilog has an edge case where an `always @*` process, which is used
to describe a combinatorial function procedurally, may not execute
at time zero because none of the signals in its implicit sensitivity
list change, i.e. when the process doesn't read any signals. This
causes the wires driven by the process to stay undefined.

The workaround to this problem (assuming SystemVerilog `always_comb`
is not available) is to introduce a dummy signal that changes only
at time zero and is optimized out during synthesis. nMigen has had
its own workaround, `$verilog_initial_trigger`, for a while. However,
`proc_prune`, while increasing readability, pulls references to this
signal out of the process. Because of this, a similar workaround was
implemented in Yosys' `write_verilog` itself.

This commit ensures we use our workaround on versions of Yosys
without the updated `write_verilog`, and Yosys' workaround on later
versions.

Fixes #418.
2020-08-26 16:51:12 +00:00
whitequark 38b75ba4bc back.cxxrtl: actualize Yosys version requirement. 2020-08-26 09:16:46 +00:00
whitequark 7aedb3e770 back.rtlil: lower maximum accepted wire size.
In practice wires of just 100000 bits sometimes have unacceptable
performance with Yosys, so stick to Verilog's minimum limit of 65536
bits.
2020-07-22 14:43:44 +00:00
whitequark d06add0aab back.rtlil: fix guard for division by zero.
Oops... that should be checking the divisor, not the dividend. This
was discovered by running the test suite on cxxsim.
2020-07-15 04:14:34 +00:00
whitequark d7a87fef42 back.pysim→sim.pysim; split into more manageable parts.
This is necessary to add cxxrtl as an alternate simulation engine.
2020-07-08 12:49:38 +00:00
whitequark 6d417568ad back.pysim: only extract signal names if VCD is requested.
This commit also fixes an issue introduced in 2606ee33 that regressed
simulator startup time and bloated VCD files. (It's actually about
10% faster now than *before* the regression was introduced.)
2020-07-08 08:33:45 +00:00
whitequark 3c3cfd48fb back.pysim: reset timeline as well.
This is a bug that was introduced in 94faf497b.
2020-07-08 08:19:29 +00:00
whitequark 90e2a991f0 back.pysim: simplify. NFC. 2020-07-08 06:31:04 +00:00
whitequark 94faf497ba back.pysim: extract timeline handling to class _Timeline. NFC. 2020-07-08 06:31:04 +00:00
whitequark d3d210eaee back.pysim: extract simulator commands to sim._cmds. NFC. 2020-07-08 05:42:33 +00:00
whitequark e435a21715 back.pysim: simplify. NFC. 2020-07-08 03:55:09 +00:00
whitequark cee43f0de1 back.pysim: simplify.
Compiled process names were never particularly useful (comments in
the source would make more sense for debugging), and coroutine
process names were actually source locations.
2020-07-07 04:29:13 +00:00
whitequark c9030eb3cd back.pysim: simplify. NFC. 2020-07-07 04:19:05 +00:00
whitequark db4529a178 back.pysim: simplify. NFC. 2020-07-07 04:09:10 +00:00
whitequark 2efeb05c63 back.pysim: synchronize waveform writing with cxxrtl. 2020-07-07 04:09:02 +00:00
whitequark e012e62ade back.pysim: synchronize terms with cxxrtl. NFC. 2020-07-07 03:38:39 +00:00
whitequark c9ac85a045 back.pysim: simplify. NFC. 2020-07-07 03:38:39 +00:00
whitequark 8f6eab0f6c back.pysim: simplify. NFC. 2020-07-07 03:38:39 +00:00
whitequark 23758e30bc Remove everything deprecated in nmigen 0.2. 2020-07-07 03:38:39 +00:00
whitequark 369bc3e307 _yosys→_toolchain.yosys 2020-07-02 18:26:08 +00:00
whitequark 2606ee33ad back.pysim: simplify.
Remove _EvalContext, which was a level of indirection serving almost
no purpose. (The only case where it would be useful is repeatedly
resetting a simulation that, each time it is reset, would create new
signals to communicate with between coroutine processes. In that case
the signal states would not be persisted in _SimulatorState, but
would be removed with the _EvalContext that is recreated each time
the simulation is reset. But this could be solved with a weak map
instead.)

This regresses simulator startup time by 10-15% for unknown reasons
but is necessary to align pysim and future cxxsim.
2020-06-28 05:04:16 +00:00
whitequark 868d49eccd back.verilog: refactor Yosys script generation. NFCI.
In commit 5f30bcbb, back.cxxsim gained a nicer way to generate
a script; this commit brings it to back.verilog too.
2020-06-14 09:38:32 +00:00
whitequark 5f30bcbb14 back.cxxrtl: allow injecting black boxes. 2020-06-14 09:25:54 +00:00
whitequark 545e49c2ca back.cxxrtl: new backend. 2020-06-11 16:19:40 +00:00
whitequark bddec3741e _yosys: translate Yosys warnings to Python warnings.
This isn't used yet (the only Yosys warning we can get is useless),
but will be handy for CXXRTL.
2020-06-11 16:12:52 +00:00
whitequark 133d4f47d1 back.verilog: remove unused imports. NFC. 2020-06-11 15:17:49 +00:00
whitequark b9799b4c4a back.verilog: fall back to nmigen_yosys package.
The nmigen-yosys PyPI package provides a custom, minimal build of
Yosys that uses (at the moment) wasmtime-py to deliver a single
WASM binary that can run on many platforms, and eliminates the need
to build Yosys from source.

Not only does this lower barrier to entry for new nMigen developers,
but also decouples nMigen from Yosys' yearly release cycle, which
lets us use new features and drop workarounds for Yosys bugs earlier.

The source for the nmigen-yosys package is provided at:
  https://github.com/nmigen/nmigen-yosys
The package is built from upstream source and released automatically
with no manual steps.

Fixes #371.
2020-05-22 16:51:00 +00:00
whitequark fbf9e1f339 back.rtlil: handle signed and large Instance parameters correctly.
Fixes #388.
2020-05-19 23:33:14 +00:00
whitequark 6e29fbcc61 back.rtlil: fix incorrect escaping of signed parameters.
Also, improve escaping code in general.
2020-04-28 02:18:45 +00:00
Teguh Hofstee ed0f508e8a
back.verilog: add workaround for evaluation Verific behavior.
The evaluation version of Verific prints its license information to stdout,
and since it is against the EULA to change that in any way, this behavior
is not possible to fix in Yosys. Add a workaround in nMigen instead.
2020-04-23 21:46:10 +00:00
Teguh Hofstee 875579ea50
back.verilog: make Yosys version check compatible with Verific. 2020-04-22 12:23:14 +00:00
anuejn ff6c0327a7
hdl.rec: make Record inherit from UserValue.
Closes #354.
2020-04-16 16:46:55 +00:00
whitequark b4af217ed0 back.rtlil: translate enum decoders to Yosys enum attributes.
Fixes #254.
2020-04-15 14:45:59 +00:00
whitequark ee73d39b8d back.rtlil: don't emit connections to zero width ports.
Fixes #335.
2020-04-13 17:04:13 +00:00
whitequark 792f35ac8f back.rtlil: refuse to create extremely large wires.
Such wires are likely to trigger pathological behavior in Yosys and,
if applicable, other toolchains that consume Verilog converted from
RTLIL.

Fixes #341.
2020-04-13 16:38:36 +00:00
whitequark 814ffde6fb back.rtlil: fix expansion of Part() for partial dummy writes.
Before this commit, selecting a part that was fully out of bounds of
a value was correctly implemented as a write to a dummy wire, but
selecting a part that was only partially out of bounds resulted in
a crash.

Fixes #351.
2020-04-13 15:56:39 +00:00
whitequark edd2bb2c49 back.rtlil: fix legalization of Part() with stride.
Also known as word_select().
2020-04-13 14:43:43 +00:00
whitequark b44870e779 Clarify a few comments. NFC. 2020-04-13 13:55:23 +00:00
Stuart Olsen 0e40dc0a2d back.pysim: Clear pending updates after they are effected 2020-04-08 14:08:35 +00:00
Stuart Olsen 1e744097ab back.pysim: Eliminate duplicate dict lookup in VCD update 2020-04-07 09:23:24 +00:00
Stuart Olsen 2398b7922e back.pysim: Reuse clock simulation commands 2020-04-07 09:23:17 +00:00
whitequark ec8386a797 back.pysim: fix emission of undriven traces to VCD files.
This has been originally implemented in commit d3775eed (which fixed
`write_vcd(traces=)` to do something at all), but had a flaw where
undriven traces would not be correctly placed in hierarchy. This
used to produce incorrect results on pyvcd 0.1, but started causing
assertion failures on pyvcd 0.2.

Fixes #345.
2020-04-03 05:20:42 +00:00
Stuart Olsen 7b9c8b440f
back.pysim: implement modulus operator. 2020-03-15 05:22:03 +00:00