1 This repository contains a proposal for the design of nMigen in form of an implementation. This implementation deviates from the existing design of Migen by making several observations of its drawbacks:
3 * Migen is strongly tailored towards Verilog, yet translation of Migen to Verilog is not straightforward, leaves much semantics implicit (e.g. signedness, width extension, combinatorial assignments, sub-signal assignments...);
4 * Hierarchical designs are useful for floorplanning and optimization, yet Migen does not support them at all;
5 * Migen's syntax is not easily composable, and something like an FSM requires extending Migen's syntax in non-orthogonal ways;
6 * Migen reimplements a lot of mature open-source tooling, such as conversion of RTL to Verilog (Yosys' Verilog backend), or simulation (Icarus Verilog, Verilator, etc.), and often lacks in features, speed, or corner case handling.
7 * Migen requires awkward specials for some FPGA features such as asynchronous resets.
9 It also observes that Yosys' intermediate language, RTLIL, is an ideal target for Migen-style logic, as conversion of FHDL to RTLIL is essentially a 1:1 translation, with the exception of the related issues of naming and hierarchy.
11 This proposal makes several major changes to Migen that hopefully solve all of these drawbacks:
13 * nMigen changes FHDL's internal representation to closely match that of RTLIL;
14 * nMigen outputs RTLIL and relies on Yosys for conversion to Verilog, EDIF, etc;
15 * nMigen uses an exact mapping between FHDL signals and RTLIL names to off-load logic simulation to Icarus Verilog, Verilator, etc;
16 * nMigen uses an uniform, composable Python eHDL;
17 * nMigen outputs hierarchical RTLIL, automatically threading signals through the hierarchy;
18 * nMigen supports asynchronous reset directly;
19 * nMigen makes driving a signal from multiple clock domains a precise, hard error.
21 This proposal keeps in mind but does not make the following major changes:
23 * nMigen could be easily modified to flatten the hierarchy if a signal is driven simultaneously from multiple modules;
24 * nMigen could be easily modified to support `x` values (invalid / don't care) by relying on RTLIL's ability to directly represent them;
25 * nMigen could be easily modified to support negative edge triggered flip-flops by relying on RTLIL's ability to directly represent them;
26 * nMigen could be easily modified to track Python source locations of primitives and export them to RTLIL/Verilog through the `src` attribute, displaying the Python source locations in timing reports directly.
28 This proposal also makes the following simplifications:
29 * Specials are eliminated. Primitives such as memory ports are represented directly, and primitives such as tristate buffers are lowered to a selectable implementation via ordinary dependency injection (`f.submodules += platform.get_tristate(triple, io)`).
31 The internals of nMigen in this proposal are cleaned up, yet they are kept sufficiently close to Migen that \~all Migen code should be possible to run directly on nMigen using a syntactic compatibility layer.
33 FHDL features currently missing from this implementation:
34 * self.clock_domains +=
40 * transformers: SplitMemory, FullMemoryWE
41 * transformers: ClockDomainsRenamer
43 `migen.genlib`, `migen.sim` and `migen.build` are missing completely.
45 One might reasonably expect that a roundtrip through RTLIL would result in unreadable Verilog.
46 However, this is not the case, e.g. consider the examples:
49 <summary>alu.v</summary>
52 module \$1 (co, sel, a, b, o);
61 assign _04_ = $signed(+ a) + $signed(- b);
65 casez ({ 1'h1, sel == 2'h2, sel == 1'h1, sel == 0'b0 })
73 { \co$next , \o$next } = _04_[16:0];
77 assign co = \co$next ;
83 <summary>alu_hier.v</summary>
114 module top(a, b, o, add_o, sub_o, op);
117 reg [15:0] \add_a$next ;
119 reg [15:0] \add_b$next ;
126 reg [15:0] \sub_a$next ;
128 reg [15:0] \sub_b$next ;
142 \add_a$next = 16'h0000;
143 \add_b$next = 16'h0000;
144 \sub_a$next = 16'h0000;
145 \sub_b$next = 16'h0000;
158 assign add_a = \add_a$next ;
159 assign add_b = \add_b$next ;
160 assign sub_a = \sub_a$next ;
161 assign sub_b = \sub_b$next ;
166 <summary>clkdiv.v</summary>
169 module \$1 (sys_clk, o);
175 (* init = 16'hffff *)
176 reg [15:0] v = 16'hffff;
178 assign _0_ = v + 1'h1;
179 always @(posedge sys_clk)
196 <summary>arst.v</summary>
199 module \$1 (o, sys_clk, sys_rst);
205 (* init = 16'h0000 *)
206 reg [15:0] v = 16'h0000;
208 assign _0_ = v + 1'h1;
209 always @(posedge sys_clk or posedge sys_rst)
225 <summary>pmux.v</summary>
228 module \$1 (c, o, s, a, b);