Open Silicon, Hands-On | Part 5: Bus and Formal → Part 6: Synthesis With Yosys → Part 7: A Real Process
Synthesis is compilation for circuits. The input is RTL, and the output is a netlist: a graph of simple gates and flip-flops wired together. The compiler analogy goes a long way. There's a front end, an intermediate representation, a pile of optimization passes and a back end that maps onto the target. It also breaks in an interesting place: the objective isn't how fast the output program runs, it's the area, delay and power of a physical thing, and the "machine code" is a cell library you haven't picked yet.
This part is generic synthesis: no library, no process. That's deliberate, because you learn a lot from what the tool does before it knows anything about silicon. Part 7 adds the library.
What Yosys does, in order
The whole generic script is six lines.
1# generic.ys -- RTL to generic gates. No technology library yet.
2read_verilog -sv rtl/acc8_isa_pkg.sv rtl/acc8_mem.sv rtl/acc8_core.sv rtl/acc8_cpu.sv rtl/acc8_wb.sv
3hierarchy -check -top acc8_wb
4synth -top acc8_wb
5check
6statThat one synth command is a macro that runs a sequence of passes. Here are the interesting ones, in the order the log shows them.
1# the passes that 'synth' ran, in order (filtered from logs/20_synth_generic.log)
27.2. Executing PROC pass (convert processes to netlists).
37.6. Executing OPT pass (performing simple optimizations).
47.7. Executing FSM pass (extract and optimize FSM).
57.8. Executing OPT pass (performing simple optimizations).
67.9. Executing WREDUCE pass (reducing word size of cells).
77.12. Executing ALUMACC pass (create $alu and $macc cells).
87.13. Executing SHARE pass (SAT-based resource sharing).
97.14. Executing OPT pass (performing simple optimizations).
107.15. Executing MEMORY pass.
117.17. Executing OPT pass (performing simple optimizations).
127.18. Executing MEMORY_MAP pass (converting memories to logic and flip-flops).
137.19. Executing OPT pass (performing simple optimizations).
147.20. Executing TECHMAP pass (map to technology primitives).
157.21. Executing OPT pass (performing simple optimizations).
167.22. Executing ABC pass (technology mapping using ABC).
177.23. Executing OPT pass (performing simple optimizations).In plain words: proc turns your always blocks into muxes and flip-flop cells. opt folds constants, merges identical cells and deletes unused logic, and it runs between nearly every other step. fsm finds state machines and recodes them. wreduce narrows cells whose upper bits are never used. alumacc groups arithmetic into adder-style cells, and share merges operators that never run at the same time. memory and memory_map handle arrays, techmap lowers everything to primitive gates, and abc optimizes and maps the resulting logic.
One option decides how far those passes can see. By default synth keeps your module hierarchy, so optimization stops at module boundaries. synth -flatten dissolves the hierarchy first, so logic can be merged and simplified across it. ASIC flows usually flatten ordinary logic for exactly that reason, and keep hard macros as opaque boxes. We'll do both in Part 7, and you'll see what flattening finds at the end of this part.
Reading stat
The stat command prints what's left. Here's the core, and the design hierarchy around it.
1=== acc8_core ===
2 +----------Local Count, excluding submodules.
3 |
4 176 cells
5 14 $_ANDNOT_
6 31 $_AND_
7 8 $_DFFE_PP_
8 6 $_DFF_P_
9 10 $_MUX_
10 46 $_NAND_
11 9 $_NOR_
12 2 $_NOT_
13 2 $_ORNOT_
14 12 $_OR_
15 13 $_SDFFE_PP0P_
16 1 $_SDFF_PP0_
17 17 $_XNOR_
18 5 $_XOR_Yosys's gate names are compact but regular. $_DFF_P_ is a plain flip-flop on the positive clock edge. $_DFFE_PP_ adds an enable. $_SDFF_PP0_ is a flop with a synchronous reset to 0, and $_SDFFE_PP0P_ is the same with an enable. The rest are the gates you'd expect, plus $_MUX_, a 2-to-1 multiplexer counted as one cell. The 28 flops are the 8 instruction-register bits, the 13 ACC, PC and ZF bits, the retire pulse, and the state machine. Notice what the table can't tell you: these cells have no area and no delay. They're Yosys's internal vocabulary, so this output answers "how many?" and never "how big?" or "how fast?"
1=== design hierarchy ===
2 +----------Count including submodules.
3 |
4 721 acc8_wb
5 13 acc8_cpu
6 176 acc8_core
7 444 acc8_memYou never wrote an adder
Software developers find this one surprising. I wrote acc_q + (is_sub ? ~mem_rdata : mem_rdata) + {7'd0, is_sub} on one line, and the tool decided how to build the adder. The alumacc pass is where it happens.
1 creating $macc model for $add$rtl/acc8_core.sv:67$16 ($add).
2 creating $macc model for $add$rtl/acc8_core.sv:46$14 ($add).
3 creating $macc model for $add$rtl/acc8_core.sv:46$13 ($add).
4 merging $macc model for $add$rtl/acc8_core.sv:46$13 into $add$rtl/acc8_core.sv:46$14.
5 creating $alu model for $macc $add$rtl/acc8_core.sv:46$14.
6 creating $alu model for $macc $add$rtl/acc8_core.sv:67$16.
7 creating $alu cell for $add$rtl/acc8_core.sv:67$16: $auto$alumacc.cc:548:replace_alu$306
8 creating $alu cell for $add$rtl/acc8_core.sv:46$14: $auto$alumacc.cc:548:replace_alu$309
9 created 2 $alu and 0 $macc cells.Two $alu cells came out: the 4-bit incrementer for the program counter, and the 8-bit adder-subtractor. The three-operand sum merged into a single $alu, with the + is_sub absorbed as the carry-in. That's the reason I wrote subtraction the two's-complement way. Then techmap lowered each $alu into full adders plus a carry-lookahead unit, and the log names the flavor it chose.
1Using template $paramod\_90_fa\WIDTH=32'00000000000000000000000000001000 for cells of type $fa.
2Using template $paramod\_90_lcu_brent_kung\WIDTH=32'00000000000000000000000000001000 for cells of type $lcu.
3Using extmapper simplemap for cells of type $pos.
4Using template $paramod\_90_fa\WIDTH=32'00000000000000000000000000000100 for cells of type $fa.
5Using template $paramod\_90_lcu_brent_kung\WIDTH=32'00000000000000000000000000000100 for cells of type $lcu.Brent-Kung is a classic parallel-prefix carry network, with fewer cells than the fastest alternatives and a logarithmic depth. It was the tool's choice, not mine. In Part 7 the timing report will show what that adder looks like after ABC has had its way with it, and it isn't the structure you'd draw on a whiteboard.
An operator is a request, not a structure
A plus sign can become a ripple chain, a lookahead tree or a carry-save compressor, depending on flags and the tool's mood. When timing matters, you stop writing operators and start choosing structures, and the choice becomes a design decision with a number attached.
Yosys rewrote my state machine
Search the log for FSM and you'll find something I didn't ask for. I wrote a three-bit binary encoding. Yosys detected the state machine, extracted it, and recoded it.
1Recoding FSM `$fsm$\state_q$238' from module `\acc8_core' using `auto' encoding:
2 mapping auto encoding to `one-hot` for this FSM.
3 000 -> -----1
4 100 -> ----1-
5 010 -> ---1--
6 001 -> --1---
7 101 -> -1----
8 011 -> 1-----Six states became six flip-flops, one per state, with exactly one set at a time. That's one-hot encoding. It usually makes next-state logic shallower and faster, at the price of more flops, which is a reasonable default for a tool to pick. But it's a design decision made behind your back, and it changes which registers exist: the state_q you debug in simulation isn't the one that gets built.
Two ways to stay in charge. synth -nofsm skips the FSM optimization entirely, and the Yosys manual describes an attribute for controlling it per register. Neither is better by default. The point is to know the recode happened, because it changes the flop count and the names in any gate-level waveform, and a property you wrote against state_q no longer maps one-to-one onto the netlist.
Know your synthesizer's defaults
Every synthesis tool makes silent choices: FSM encoding, memory mapping, resource sharing, flattening. Skim the log for them the first time you synthesize a block, write down the ones that matter, and pin the choices you care about with flags or attributes.
Memory inference
The memory is the biggest thing in the design, so it deserves a close look. Here's what Yosys makes of acc8_mem after just proc and memory -nomap, which infers the memory but stops before turning it into logic.
1 cell $mem_v2 \cells
2 parameter \MEMID "\\cells"
3 parameter \WIDTH 8
4 parameter \OFFSET 0
5 parameter \SIZE 16
6 parameter \ABITS 4
7 parameter \RD_PORTS 1
8 parameter \RD_CLK_ENABLE 1'1
9 parameter \RD_CLK_POLARITY 1'1
10 parameter \RD_TRANSPARENCY_MASK 1'0The array arrives as a single $mem_v2 cell: 8 bits wide, 16 words deep, 4 address bits, with a clocked read port. The register I wrote after the read, rdata <= cells[addr], was absorbed into the memory cell as a synchronous read port. The same log line also reports that the write port is non-transparent, which means a read of an address being written returns the old value. That's a real behavior to check against whatever memory you target later. Macros and FPGA block RAMs each have their own rules for same-address reads and writes, and a mismatch there is a classic source of "it simulated fine" surprises.
Checking read port `\cells'[0] in module `\acc8_mem': merging output FF to cell.
Write port 0: non-transparent.memory_map then expands that single cell into real flops: 128 enable-flops for the bits, write-enable decoding, and a read multiplexer tree. That's fine at 16 bytes. At a few kilobytes it's absurd, which is why real flows swap in memory macros (Part 7) or FPGA block RAM (Part 8) for anything big.
What ABC does, and why gate counts are upper bounds
The last big step is ABC, a separate logic-synthesis engine that Yosys calls. It rebuilds your combinational logic as a compact graph, applies rewriting and sharing, and maps the result onto a gate set. Since we haven't chosen a cell library, the "gate set" is Yosys's own primitives.
Here's the same design through three recipes.
1hierarchical + ABC 545 gates 176 flops 721 total
2flattened + ABC 543 gates 175 flops 718 total
3flattened, no ABC 458 gates 175 flops 633 totalLook closely. Skipping ABC gave fewer cells, 633 against 718. That isn't ABC making things worse. A $_MUX_ is one cell in the unoptimized netlist, while the mapped netlist expresses the same function as several smaller gates, so the unit being counted changed under my feet. The gate count is a unit of the recipe, not of the silicon.
The other difference is quieter. Flattening the hierarchy removed one flip-flop, 176 to 175. The retire pulse exists for testbenches, and the bus wrapper never uses it, so once the tool could see across the module boundary it deleted the register that fed nothing.
Don't compare gate counts across recipes
A generic cell count is an upper bound with fuzzy units: it moves with flattening, with ABC on or off, and with how muxes and XORs are counted. Compare designs by area from a real cell library, and compare them under the same script. Part 7 does exactly that.
Checks you shouldn't skip
Synthesis tools forgive a lot, and the forgiveness is where the damage hides. After synthesis, run check, which looks for undriven wires, wires with multiple drivers, combinational loops and similar structural trouble. A warning here usually means a real bug upstream: an output nobody drives, or two blocks fighting over one signal. This run is clean.
1Checking module acc8_wb...
2Checking module acc8_cpu...
3Checking module acc8_core...
4Checking module acc8_mem...
5Found and reported 0 problems.In CI, check -assert turns any finding into a failure, and that's how Part 8 uses it. Two small reading notes while you're in the log. Flattened netlists contain a few $scopeinfo cells, which are hierarchy bookkeeping and not logic, so don't count them. And whenever an area or cell figure matters, write down the exact script that produced it, because as you've just seen, the recipe is part of the number.
"A synthesis result without its script is an anecdote."
Now for the part where numbers get real. In Part 7 we map onto the SkyWater 130 nm standard cells, read an area report in square micrometres, get a pre-layout speed estimate from the critical path, and measure how much a one-flop change is worth.