Commit graph

1643 commits

Author SHA1 Message Date
Catherine
738d8b7764 hdl: deprecate {Const,Signal}.{width,signed} accessors.
These accessors used to be necessary (in addition to `.shape()`) while
the AST nodes were mutable. However, after commit 2bf1b4da that made
AST nodes immutable, there is no technical requirement to keep them
around. Additionally:

- `len(value)` is shorter than `value.width` and works with any `value`
- `value.shape().signed` is longer than `value.signed` but works with
  any `value`
2024-03-26 22:56:17 +00:00
Wanda
0c041f2602 hdl._ir: rename Instance.named_ports to Instance.ports.
Made possible by the new port propagation code freeing up the name.
2024-03-26 20:36:12 +00:00
Thomas Watson
fa2adbef84 hdl.dsl: use private names for FSM ongoing signals 2024-03-25 19:15:24 +00:00
Thomas Watson
c7f719ab93 hdl.ast: allow Signals to be privately named using name=""
* Given a private name `$\d+` in RTLIL (as they are not named in the IR)

* Not automatically added to VCD files (as they are not named in the IR)

* Cannot be traced to a VCD (as they have no name to put in the file)

* Cannot be used with an unnamed top-level port (as there is no name)
2024-03-25 19:15:24 +00:00
Wanda
6ffafef794 lib.memory: raise an error on mutating already-elaborated memory. 2024-03-25 18:40:20 +00:00
Catherine
3d5c36a606 docs/reference: finish Value section. 2024-03-25 16:03:55 +00:00
Wanda
cd51e02de2 lib.wiring: remove stray references to signature freezing. 2024-03-25 14:15:53 +00:00
Wanda
efcd9a4538 hdl._ast: fix _value_repr computation.
Fixes fallout from #1165.
2024-03-25 13:53:39 +00:00
Catherine
11f7b887ad sim: write process commands to VCD file.
If delta cycles are expanded (i.e. if the `fs_per_delta` argument to
`Simulator.write_vcd` is not zero), then create a string typed variable
for each testbench in the simulation, which reflects the current
command being executed by that testbench. To make all commands visible,
insert a (visual) delta cycle after each executed command, and ensure
that there is a change/crossing point in the waveform display each time
a command is executed, even if several identical ones in a row.

If delta cycles are not expanded, the behavior is unchanged.
2024-03-24 12:21:32 +00:00
Catherine
36fb9035e4 sim: allow visualizing delta cycles in VCD dumps.
This commit adds an option `fs_per_delta=` to `Simulator.write_vcd()`.
Specifying a positive integer value for it causes the simulator to
offset value change times by that many femtoseconds for each delta
cycle after the last timeline advancement.

This option is only suitable for debugging. If the timeline is advanced
by less than the combined duration of expanded delta cycles, an error
similar to the following will be raised:

    vcd.writer.VCDPhaseError: Out of order timestamp: 62490

Typically `fs_per_delta=1` is best, since it allows thousands of delta
cycles to be expanded without risking a VCD phase error, but bigger
values can be used for an exaggerated visual effect.

Also, the VCD writer is changed to use 1 fs as the timebase instead of
1 ps. This change is largely invisible to designers, resulting only in
slightly larger VCD files due to longer timestamps.

Since the `fs_per_delta=` option is per VCD writer, it is possible to
simultaneously dump two VCDs, one with and one without delta cycle
expansion:

    with sim.write_vcd("sim.vcd"), sim.write_vcd("sim.d.vcd", fs_per_delta=1):
        sim.run()
2024-03-24 12:07:49 +00:00
Catherine
0cb71f8c57 sim: only preempt testbenches on explicit wait.
Before this commit, testbenches (generators added with `add_testbench`)
were not only preemptible after any `yield`, but were *guaranteed* to
be preempted by another testbench after *every* yield. This is evil:
if you have any race condition between testbenches, which is common,
this scheduling strategy will maximize the resulting nondeterminism by
interleaving your testbench with every other one as much as possible.
This behavior is an outcome of the way `add_testbench` is implemented,
which is by yielding `Settle()` after every command.

One can observe that:
- `yield value_like` should never preempt;
- `yield assignable.eq()` in `add_process()` should not preempt, since
  it only sets a `next` signal state, or appends to `write_queue` of
  a memory state, and never wakes up processes;
- `yield assignable.eq()` in `add_testbench()` should only preempt if
  changing `assignable` wakes up an RTL process. (It could potentially
  also preempt if that wakes up another testbench, but this has no
  benefit and requires `sim.set()` from RFC 36 to be awaitable, which
  is not desirable.)

After this commit, `PySimEngine._step()` is implemented with two nested
loops instead of one. The outer loop iterates through every testbench
and runs it until an explicit wait point (`Settle()`, `Delay()`, or
`Tick()`), terminating when no testbenches are runnable. The inner loop
is the usual eval/commit loop, running whenever a testbench changes
design state.

`PySimEngine._processes` is a `set`, which doesn't have a deterministic
iteration order. This does not matter for processes, where determinism
is guaranteed by the eval/commit loop, but causes racy testbenches to
pass or fail nondeterministically (in practice depending on the memory
layout of the Python process). While it is best to not have races in
the testbenches, this commit makes `PySimEngine._testbenches` a `list`,
making the outcome of a race deterministic, and enabling a hacky work-
around to make them work: reordering calls to `add_testbench()`.

A potential future improvement is a simulation mode that, instead,
randomizes the scheduling of testbenches, exposing race conditions
early.
2024-03-24 11:53:18 +00:00
Sage Walker
9ed83b6aff sim.core: correct deprecation warning 2024-03-22 23:48:44 +00:00
Catherine
6ce82848d9 lib.memory: Memory.{r,w}_ports.{read,write}_ports.
The abbreviated form was initially added to match `lib.fifo`, but it
looks very out of place on `lib.memory`, and we may be moving away from
such heavy use of abbreviations anyway.

While technically a breaking change, these attributes have very narrow
usefulness and so this change qualifies as "minor".
2024-03-22 23:05:42 +00:00
Catherine
2333c5f0af lib.memory: expand Memory.Init.__repr__().
Display `shape` and `depth` also. `depth` is redundant although useful
for ease of reading (there are always `depth` elements shown), but
`shape` was just lost.
2024-03-22 23:05:42 +00:00
Catherine
fc84b8decf lib.memory: remove Memory.Init.depth.
This attribute is fully redundant with `.__len__()`, and is out of place
on a `list`-like container like `Memory.Init`.

The `.shape` attribute, however, provides a unique function.
2024-03-22 23:05:42 +00:00
Catherine
2640033316 lib.memory: thread src_loc_at in {read,write}_port. 2024-03-22 23:05:42 +00:00
Catherine
b8b1e7081b lib.memory: improve and regularize diagnostics. 2024-03-22 23:05:42 +00:00
Catherine
8d44ec513d lib.memory: improve and finish documentation. 2024-03-22 23:05:42 +00:00
Catherine
8faa6facfb lib.memory: reorder classes and functions. NFC 2024-03-22 23:05:42 +00:00
Catherine
e3c9296813 docs: introduce custom "Members" section, for lib.wiring signatures. 2024-03-22 23:05:42 +00:00
Catherine
6b512520ff docs: upgrade sphinx-rtd-theme, work around readthedocs/sphinx_rtd_theme#1301. 2024-03-22 23:05:42 +00:00
Catherine
8861b8a3eb docs/reference: fix typos. 2024-03-22 06:07:19 +00:00
Wanda
456dcaeb7b lib.io: Implement *Buffer from RFC 55. 2024-03-22 01:44:25 +00:00
Catherine
81eae1dd35 docs/install: link to YoWASP. 2024-03-22 01:22:02 +00:00
Catherine
12b4b1891a docs/install: link to playground. 2024-03-22 01:22:02 +00:00
Catherine
2ab3a4a0a0 docs/install: fix Yosys version requirement. 2024-03-22 01:22:02 +00:00
Wanda
8c65a79cdd hdl._ir: Remove support for non-Elaboratable elaboratables.
Fixes #1216.
2024-03-20 08:20:23 +00:00
Catherine
2569886464 lib.wiring: minor ReST syntax fixes. 2024-03-19 14:17:37 +00:00
Wanda
d6bf47d549 Implement RFC 51: Add ShapeCastable.from_bits and amaranth.lib.data.Const.
Co-authored-by: Catherine <whitequark@whitequark.org>
2024-03-19 04:01:26 +00:00
Wanda
598cf8db28 lib.io: Implement *Port from RFC 55. 2024-03-18 23:56:34 +00:00
Wanda
744576011f Implement RFC 53: Low-level I/O primitives.
Co-authored-by: Catherine <whitequark@whitequark.org>
Co-authored-by: mcclure <mcclure@users.noreply.github.com>
2024-03-18 20:33:22 +00:00
Wanda
18b54ded0a hdl._ir: Fix fallout from #1190, add more tests. 2024-03-16 14:17:00 +00:00
Wanda
23f1b63425 lib.memory: Add Signature.create implementations. 2024-03-16 08:48:32 +00:00
Catherine
83701d74cf CI: automatically publish GitHub releases. 2024-03-15 12:22:12 +00:00
Catherine
11ec35d258 lib.wiring: remove unnecessary flipping in Signature.flatten. 2024-03-15 10:35:50 +00:00
Catherine
3e6e78012d CI: fail document job on warnings. 2024-03-14 06:10:14 +00:00
Catherine
add7d70050 docs/guide: fix incorrect reference. 2024-03-14 06:10:14 +00:00
Wanda
49dee891e8 tests: Exorcise some star-imports. 2024-03-13 18:03:22 +00:00
mcc
27ca96383e utils: F-strings are missing the letter "f"
Also adds tests for utils ValueError strings.
2024-03-13 14:56:27 +00:00
Wanda
5edff532a8 sim: Do not direct user to deprecated add_sync_process. 2024-03-13 13:12:34 +00:00
Wanda
455a7bc6c8 lib.memory: Allow setting Memory.init.
The `init` property is already mutable, so this adds no actual new
functionality, just convenience.
2024-03-13 13:12:15 +00:00
Wanda
cb96b15b8c hdl._ir: Remove all support for fragment flattening. 2024-03-11 21:28:46 +00:00
Wanda
bfe541a6d7 Implement RFC 50: Print and string formatting.
Co-authored-by: Catherine <whitequark@whitequark.org>
2024-03-11 09:42:43 +00:00
Jean-François Nguyen
715a8d4934 lib.memory: strip whitespace. 2024-03-08 15:47:21 +00:00
Wanda
7e291a26e3 docs: Add more links for past releases. 2024-03-08 03:54:34 +00:00
Wanda
161b01450e hdl._ast, hdl._ir: Deduplicate shape unification logic. NFC 2024-03-05 12:24:02 +00:00
Wanda
31a12c03d1 hdl._ir: Remove support for the nonexistent unary "+" operator. 2024-03-03 23:51:38 +00:00
Wanda
c2001fe935 vendor: Rename IntelPlatform to AlteraPlatform.
Fixes #1179.
2024-03-03 22:52:58 +00:00
Wanda
127fe1fd2e hdl._xfrm: Get rid of _insert_resets, move the logic downstream. 2024-03-03 19:34:35 +00:00
Wanda
ea561378ac hdl._nir: Remove ArrayMux, use AssignmentList instead. 2024-03-03 18:52:21 +00:00