Commit graph

234 commits

Author SHA1 Message Date
whitequark 27b47faf16 hdl.ast: add Value.{as_signed,as_unsigned}.
Before this commit, there was no way to do so besides creating and
assigning an intermediate signal, which could not be extracted into
a helper function due to Module statefulness.

Fixes #292.
2020-02-06 18:27:55 +00:00
whitequark 882fddfa96 back.pysim: emit toplevel inputs in VCD files as well.
Before this commit, only signals driven from fragments (in practice,
everything except toplevel inputs) would get written to a VCD file.
Not having toplevel inputs in the dump made debugging ~impossible.

After this commit, all signals the fragment refers to get written to
a VCD file. (More specifically, all signals the compiler assigns
an index to, i.e. signals the generated code reads or writes.)

Fixes #280.
2020-02-06 17:19:47 +00:00
whitequark d3775eedd7 back.pysim: make write_vcd(traces=) actually use those traces.
Reported in #280.
2020-02-06 17:07:48 +00:00
whitequark 31cd72c0b6 hdl.mem: add synthesis attribute support.
Fixes #291.
2020-02-06 14:53:16 +00:00
whitequark 49758a3a0c hdl.ast: prohibit shifts by signed value.
These are not desirable in a HDL, and currently elaborate to broken
RTLIL (after YosysHQ/yosys#1551); prohibit them completely, like
we already do for division and modulo.

Fixes #302.
2020-02-01 23:04:25 +00:00
whitequark 3ac13eb8f9 back.rtlil: don't emit wires for empty signals.
Fixes #312.
2020-01-31 03:38:58 +00:00
whitequark 476ce15f04 back.rtlil: do not consider unreachable array elements when legalizing.
Otherwise we produce invalid RTLIL.
2020-01-01 15:26:05 +00:00
whitequark 7650431996 back.pysim: fix miscompilation of Signal(unsigned) - Signal(signed). 2019-12-02 18:52:55 +00:00
whitequark 7df70059d1 back.pysim: redesign the simulator.
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 #28.
Fixes #34.
Fixes #160.
Fixes #161.
Fixes #215.
Fixes #242.
Fixes #262.
2019-11-28 21:05:34 +00:00
whitequark f8428ff505 back.rtlil: infer bit width for instance parameters.
Otherwise, Yosys assumes it is always 32, which is often
inappropriate.
2019-11-27 17:58:42 +00:00
whitequark 7c322e562a back.rtlil: extend shorter operand of a binop when matching sign.
This is necessary because converting a large unsigned value to
a signed value of the same width may change its sign.

Fixes #271.
2019-11-18 10:39:55 +00:00
whitequark 4d6ad28f59 back.verilog: remove $verilog_initial_trigger after proc_prune.
$verilog_initial_trigger was introduced to work around Verilog
simulation semantics issues with `always @*` statements that only
have constants on RHS and in conditions. Unfortunately, it breaks
Verilator. Since the combination of proc_prune and proc_clean passes
eliminates all such statements, it can be simply removed when both
of these passes are available, currently on Yosys master. After
Yosys 0.10 is released, we can get rid of $verilog_initial_trigger
entirely.
2019-10-28 10:11:41 +00:00
whitequark 8b05b28f5a back.rtlil: avoid exponential behavior when legalizing Part().
Fixes #259.
2019-10-26 02:01:53 +00:00
whitequark ffd10e3042 back.rtlil: fix lowering of Part() on LHS to account for stride. 2019-10-26 01:52:34 +00:00
Sebastien Bourdeauducq 07b3510218 verilog: fix yosys version error message 2019-10-16 13:10:19 +08:00
whitequark 58300d8eb6 back.verilog: fix Yosys version check. 2019-10-16 02:25:35 +00:00
whitequark 2f9dab361f {,_}tools→{,_}utils
In context of nMigen, "tools" means "parts of toolchain", so it is
confusing to have a completely unrelated module also called "tools".
2019-10-13 18:53:38 +00:00
whitequark a7e3b80409 hdl.ast: rename Slice.end back to Slice.stop.
It used to be called .stop in oMigen, and it's also called .stop in
Python range and slice objects, so keep that.
2019-10-12 22:40:48 +00:00
whitequark da48c05bdf _tools: extract most utility methods to a private package.
We don't want to guarantee backwards compatibility for most of them.
2019-10-12 22:40:48 +00:00
Jean-François Nguyen a97003d57a back.rtlil: fix DeprecationWarning. NFC. 2019-10-12 21:50:40 +00:00
whitequark a658cb2bbf hdl.ast: deprecate shapes like (1, True) in favor of signed(1).
This is a great improvement in clarity.
2019-10-11 13:22:08 +00:00
whitequark db960e7c30 Consistently use {!r}, not '{!r}' in diagnostics.
This can cause confusion:
  * If the erroneous object is None, it is printed as 'None', which
    appears as a string (and could be the result of converting None
    to a string.)
  * If the erroneous object is a string, it is printed as ''<val>'',
    which is a rather strange combination of quotes.
2019-10-11 11:47:42 +00:00
whitequark fa1e466a65 hdl.ast: Operator.{op→operator}
Both "operator" and "operand" were shortened to "op" in different
places in code, which caused confusion.
2019-10-11 11:37:26 +00:00
whitequark 8021e2dd76 vendor.intel: add Quartus support.
Co-authored-by: Dan Ravensloft <dan.ravensloft@gmail.com>
2019-10-10 00:35:13 +00:00
whitequark 2512a9a12d back.rtlil: don't crash legalizing values with no branches.
Fixes #239.
2019-10-06 08:52:49 +00:00
whitequark 964c67453f back.rtlil: avoid unsoundness for division by zero.
Fixes #238.
2019-10-04 08:15:45 +00:00
whitequark d139f340b3 back.rtlil: don't cache wires for legalized switch tests.
This causes miscompilation of code such as:

  r = Array([self.a, self.b])
  m = Module()
  with m.If(r[self.s]):
      m.d.comb += self.o.eq(1)
  return m
2019-10-02 07:51:49 +00:00
whitequark d3f7cc8ed2 back.rtlil: sign of rhs and lhs of ${sshr,sshl,pow} don't need to match. 2019-10-02 03:50:20 +00:00
whitequark 3a1dae591b back.rtlil: it is not necessary to match binop operand width. 2019-10-02 03:38:58 +00:00
whitequark 1621ceb65a hdl.ast: actually implement the // operator. 2019-09-28 19:33:24 +00:00
whitequark e3a1d05f23 back.rtlil: fix handling of certain nested arrays.
This triggers on code like:

c1 = Signal()
c2 = Signal()
c3 = Signal()
v1 = Array([Const(1, 8), Const(2, 8)])[c1]
v2 = Array([Const(3, 8), Const(4, 8)])[c2]
v3 = Array([v1, v2])[c3]

Fixes #226.
2019-09-24 18:32:26 +00:00
whitequark 53bb4300a3 build.plat: strip internal attributes from Verilog output.
Although useful for debugging, most external tools often complain
about such attributes (with notable exception of Vivado). As such,
it is better to emit Verilog with these attributes into a separate
file such as `design.debug.v` and only emit the attributes that were
explicitly placed by the user to `design.v`.

This still leaves the (*init*) attribute. See #220 for details.
2019-09-24 14:56:00 +00:00
whitequark 7777b7b98c back.rtlil: give predictable names to anonymous subfragments.
This is required for applying constraints to clocks in anonymous
subfragments in build.plat.
2019-09-23 12:48:02 +00:00
whitequark 378e924280 hdl.ast: rename nbits to width.
Also, replace `bits, sign = x.shape()` with more idiomatic
`width, signed = x.shape()`.

This unifies all properties corresponding to `len(x)` to `x.width`.
(Not all values have a `width` property.)

Fixes #210.
2019-09-20 15:36:25 +00:00
whitequark 7f6b3f93f5 back.pysim: fix simulation of Value.xor(). 2019-09-20 10:12:59 +00:00
whitequark 32310aecad hdl.ast: add Value.xor, mapping to $reduce_xor.
Fixes #147.
2019-09-13 14:29:46 +00:00
whitequark b23a9794a4 hdl.ast: add Value.{any,all}, mapping to $reduce_{or,and}.
Refs #147.
2019-09-13 13:14:52 +00:00
whitequark d1779bdb59 back: return name map from convert_fragment(). 2019-09-11 23:22:12 +00:00
whitequark 943ce317af hdl.ast,back.rtlil: implement Cover.
Fixes #194.
2019-09-03 01:32:24 +00:00
whitequark 2e20622046 hdl.cd: add negedge clock domains.
Fixes #185.
2019-08-31 22:05:48 +00:00
Emily c4e8ac734f _toolchain,build.plat,vendor.*: add required_tools list and checks. 2019-08-31 00:05:47 +00:00
whitequark b14f5572d8 _toolchain: new module, for injecting dependencies in e.g. Nix. 2019-08-28 11:32:18 +00:00
whitequark 2168ff512b back.verilog: bump Yosys version requirement to 0.9.
Fixes #55.
2019-08-26 09:59:40 +00:00
whitequark 72cf4ca991 back.pysim: implement sim.add_clock(if_exists=True). 2019-08-23 08:53:48 +00:00
whitequark 906385c7f8 back.pysim: don't crash when trying to drive a nonexistent domain clock. 2019-08-23 08:37:59 +00:00
whitequark 47bad3d20e back.rtlil: print real parameters with maximum precision. 2019-08-22 04:42:30 +00:00
Darrell Harmon aefde85031 back.rtlil: add support for real (float) parameters on Instances.
Required for Xilinx MMCME2_BASE, etc.
2019-08-22 04:13:05 +00:00
whitequark 1fc63a62c0 back.pysim: allow coroutines as processes.
This is a somewhat obscure use case, but it is possible to use async
functions with pysim by carefully using @asyncio.coroutine. That is,
async functions can call back into pysim if they are declared in
a specific way:

  @asyncio.coroutine
  def do_something(self, value):
    yield self.reg.eq(value)

which may then be called from elsewhere with:

  async def test_case(self):
    await do_something(0x1234)

This approach is unfortunately limited in that async functions
cannot yield directly. It should likely be improved by using async
generators, but supporting coroutines in pysim is unobtrustive and
allows existing code that made use of this feature in oMigen to work.
2019-08-21 03:30:37 +00:00
whitequark 5ad409e897 back.verilog: parse output of yosys -V.
See #55.
2019-08-19 23:28:33 +00:00
whitequark a069d975b2 lib.cdc: use a local clock domain in ResetSynchronizer.
This reverts commit 779f3ee906.
This reverts commit 300d47ca2e.
This reverts commit 9c54d0c061.
2019-08-19 21:45:08 +00:00