Close-up of red circuit-board traces with rows of solder pads on a black board
Technology Nov 03, 2026 • 13 min read

Open Silicon, Hands-On, Part 3: RTL That Actually Synthesizes

Write the CPU in SystemVerilog the synthesizable way: a four-clock FSM, no latches, a deliberate reset strategy, and lint as a gate you can't skip.

Share:
Lee Foropoulos

Lee Foropoulos

13 min read

Continue where you left off?
Text size:

Contents

Open Silicon, Hands-On | Part 2: A Golden Model → Part 3: RTL That Synthesizes → Part 4: Co-Simulation

RTL looks like code and isn't. In software you give a machine instructions and it executes them in order. In RTL you describe a circuit that exists all at once, and the clock decides when its registers notice anything. That's why the failure modes differ. A software bug is a wrong instruction. An RTL bug can be a wrong circuit: one that simulates beautifully and then builds into something you never meant.

This part writes the acc8 core in SystemVerilog and uses two cheap tools, a linter and a synthesis frontend, to catch the classic mistakes before any testbench has run.

Colorful source code on a dark monitor
SystemVerilog is typed like code, but you aren't giving the machine instructions. You're drawing a circuit.

Think in registers and wires

SystemVerilog gives you two block types that matter. always_ff @(posedge clk) describes registers: elements that capture a new value on the clock edge, assigned with the nonblocking <=. always_comb describes combinational logic: a pure function of its inputs, assigned with =, with no memory of its own. Nearly everything else is syntax around those two ideas.

The pattern I use for every control machine is the two-process style. A combinational block computes where the machine wants to go next (signals ending in _d), and a clocked block stores it (signals ending in _q). The suffixes cost nothing and make every waveform readable: _q is what a flop holds now, _d is what it will hold after the next edge.

In RTL there is no "then." A combinational block is everything at once, and a clocked block is everything on the edge.

Spec the micro-architecture before the code

The model said what acc8 does. The RTL also has to say how: how many clocks, and which resources are busy when. Ours is the simplest design that's honest about memory. Every instruction takes four clocks, always, in a fixed rhythm.

StateThe clock's jobMemory port
IDLEwait for startowned by the host
FETCHpresent the PC to the memoryaddress = PC
LATCHcapture the instruction word, step the PCdata arrives, address ignored
OPERANDpresent the operand addressaddress = operand
EXECuse the operand data; write ACC, ZF or PC, or storewrite enable for STA
HALTstay put until resetowned by the host

Why a synchronous-read memory? Because that's what real SRAM macros give you: present an address, and the data arrives one clock later. If a core assumes the data shows up in the same clock, it can only be built on flip-flop arrays. If it assumes a one-clock delay, the same RTL sits on flops, an FPGA block RAM or a generated macro. In Part 7 we'll swap a macro in without touching the core.

Fixed timing has a second payoff. The model can predict the cycle count, so the testbench will check timing for free.

4
clocks for every instruction, always, so the model can predict cycle counts and the testbench can check them for free
A wooden toy train set with a small station, track and trees
A finite-state machine is a toy railway: a handful of stations, one train, and strict rules about which track connects to which.

The core, in about sixty lines

Here's the heart of acc8_core.sv. First the adder: one shared adder-subtractor, because A − B is just A + ~B + 1.

systemverilog
1  // one shared adder/subtractor: A - B is A + ~B + 1
2  logic       is_sub;
3  logic [7:0] alu_y;
4  assign is_sub = (op == acc8_isa_pkg::OP_SUB);
5  assign alu_y  = acc_q + (is_sub ? ~mem_rdata : mem_rdata) + {7'd0, is_sub};

And the combinational block that does all the deciding.

systemverilog
1  always_comb begin
2    // Defaults first: every output is assigned on every path, so nothing can latch.
3    state_d   = state_q;
4    pc_d      = pc_q;
5    mem_addr  = arg;              // the operand address, except during FETCH
6    mem_we    = 1'b0;
7    result    = 8'd0;
8    wr_acc    = 1'b0;
9
10    case (state_q)
11      S_IDLE:    if (start) state_d = S_FETCH;
12      S_FETCH: begin
13        mem_addr = pc_q;
14        state_d  = S_LATCH;
15      end
16      S_LATCH: begin
17        pc_d    = pc_q + 4'd1;
18        state_d = S_OPERAND;
19      end
20      S_OPERAND: state_d = S_EXEC;
21      S_EXEC: begin
22        state_d = S_FETCH;
23        case (op)
24          acc8_isa_pkg::OP_LDA: begin result = mem_rdata;   wr_acc = 1'b1; end
25          acc8_isa_pkg::OP_ADD: begin result = alu_y;       wr_acc = 1'b1; end
26          acc8_isa_pkg::OP_SUB: begin result = alu_y;       wr_acc = 1'b1; end
27          acc8_isa_pkg::OP_LDI: begin result = {4'd0, arg}; wr_acc = 1'b1; end
28          acc8_isa_pkg::OP_STA: mem_we = 1'b1;
29          acc8_isa_pkg::OP_JMP: pc_d = arg;
30          acc8_isa_pkg::OP_JZ:  if (zf_q) pc_d = arg;
31          acc8_isa_pkg::OP_HLT: state_d = S_HALT;
32          default:              state_d = S_HALT;   // reserved opcodes stop the machine too
33        endcase
34      end
35      S_HALT:    state_d = S_HALT;                // only reset leaves
36      default:   state_d = S_IDLE;                // the two unused encodings
37    endcase
38
39    acc_d = wr_acc ? result : acc_q;
40    zf_d  = wr_acc ? (result == 8'd0) : zf_q;
41  end

Three habits here are worth copying. First, defaults at the top: every signal this block drives is assigned before the case, so no path can leave one unassigned. Second, the case on state is exhaustive, with a default that recovers from the two unused 3-bit encodings instead of wandering off. Third, opcodes are referenced through the generated package, acc8_isa_pkg::OP_STA, never as bare numbers.

The clocked half is dull on purpose. Every _d becomes a _q, with a synchronous reset on top, plus one register that has no reset at all (more on that below).

systemverilog
1  always_ff @(posedge clk) begin
2    if (rst) begin
3      state_q  <= S_IDLE;
4      pc_q     <= 4'd0;
5      acc_q    <= 8'd0;
6      zf_q     <= 1'b0;
7      retire_q <= 1'b0;
8    end else begin
9      state_q  <= state_d;
10      pc_q     <= pc_d;
11      acc_q    <= acc_d;
12      zf_q     <= zf_d;
13      retire_q <= (state_q == S_EXEC);
14    end
15  end
16
17  always_ff @(posedge clk)
18    if (state_q == S_LATCH) ir_q <= mem_rdata;

The memory is smaller still: a synchronous-read array in a dozen lines.

systemverilog
1module acc8_mem (
2  input  logic       clk,
3  input  logic       we,
4  input  logic [3:0] addr,
5  input  logic [7:0] wdata,
6  output logic [7:0] rdata
7);
8  logic [7:0] cells [16];
9
10  always_ff @(posedge clk) begin
11    if (we) cells[addr] <= wdata;
12    rdata <= cells[addr];            // read-before-write: a write shows up next read
13  end
14endmodule

Name your flops

A _q suffix on every register and a _d on every next-state signal costs nothing and pays back in waveforms, lint output and formal traces. Pick a convention, write it down, and enforce it in review.

One language, two parsers

The first time I pushed this RTL through both tools I use, I got a surprise. Verilator was happy with the standard way to bring a package into a module: import acc8_isa_pkg::*; placed in the module header. Yosys, whose built-in Verilog frontend supports a useful subset of SystemVerilog, answered syntax error, unexpected TOK_IMPORT. Moving the import into the module body didn't help.

text
3. Executing Verilog-2005 frontend: rtl/acc8_core.sv
rtl/acc8_core.sv:22: ERROR: syntax error, unexpected TOK_IMPORT

I reduced it to a three-line probe and tried the three obvious spellings against both tools.

text
1# three ways to name a package constant: does each parser accept the file?
2== t1: // variant 1: file-scope import
3   yosys exit=0
4   verilator exit=0
5== t2: // variant 2: qualified names
6   yosys exit=0
7   verilator exit=0
8== t3: // variant 3: import in header (standard SV)
9   yosys:    t3.sv:2: ERROR: syntax error, unexpected TOK_IMPORT, expecting '#' or '(' or ';'
10   yosys exit=1
11   verilator exit=0

Package-qualified names (acc8_isa_pkg::OP_LDA) work in both, so that's what the core uses. If you know C++, think of it as writing std:: everywhere because one of your compilers rejects using namespace std;. It's slightly noisier and completely portable.

The lesson is bigger than imports. Your simulator, linter, synthesizer and formal tool are four separate parsers with four opinions about SystemVerilog. A design that's clean in one can be unreadable in another, and the discovery always arrives at the worst moment.

Run every tool on day one

Push the smallest possible file through every tool you plan to use, including the synthesizer and the formal front end, before you write a thousand lines. Language-subset surprises are cheap on day one and expensive in week six.

Latches: the bug simulation can't see

A latch is memory you didn't ask for. If a combinational block doesn't assign a signal on every path, the circuit has to remember the old value on the paths you forgot, and the synthesizer builds a level-sensitive storage element to do it. The simulation looks fine. The hardware has a timing hazard you'll never find from the waveforms.

I'll break the core on purpose. Delete the two default assignments at the top of the always_comb block and ask Verilator for its opinion.

text
1+ diff -u rtl/acc8_core.sv bugs/latch/acc8_core.sv
2@@ -54,8 +54,6 @@
3     pc_d      = pc_q;
4     mem_addr  = arg;              // the operand address, except during FETCH
5     mem_we    = 1'b0;
6-    result    = 8'd0;
7-    wr_acc    = 1'b0;
8
9     case (state_q)
10       S_IDLE:    if (start) state_d = S_FETCH;
text
1%Warning-LATCH: bugs/latch/acc8_core.sv:51:3: Latch inferred for signal 'acc8_cpu.u_core.result' (not all control paths of combinational always assign a value)
2                                            : ... Suggest use of always_latch for intentional latches
3%Warning-LATCH: bugs/latch/acc8_core.sv:51:3: Latch inferred for signal 'acc8_cpu.u_core.wr_acc' (not all control paths of combinational always assign a value)
4                                            : ... Suggest use of always_latch for intentional latches
5%Warning-LATCH: bugs/latch/acc8_core.sv:51:3: Latch inferred for signal 'acc8_cpu.u_core.acc_d' (not all control paths of combinational always assign a value)
6                                            : ... Suggest use of always_latch for intentional latches
7%Warning-LATCH: bugs/latch/acc8_core.sv:51:3: Latch inferred for signal 'acc8_cpu.u_core.zf_d' (not all control paths of combinational always assign a value)
8                                            : ... Suggest use of always_latch for intentional latches
9%Error: Exiting due to 4 warning(s)
10exit=1

Two deleted lines, four latches: the two signals I stopped defaulting, plus acc_d and zf_d, which depend on them. Verilator names every one. A testbench can sail straight past this design: with every flop starting at zero, the latched values happen to be harmless. Part 4 shows that happening, and shows the one-flag change that exposes it.

4
latches inferred by deleting two lines from one combinational block, each named by lint in the same second

A latch simulates fine

Simulators model a latch exactly as written, so it passes tests while hiding a real hazard in silicon. The cure is procedural: assign a default to every output before the case, write always_comb so the tools know your intent, and never silence the latch warning.

A hand probing a blue circuit board lit from below with a pen-like tool
Lint is the multimeter you can use before the board exists. It can't prove the design works, but it finds the classic mistakes in milliseconds.
A latch is memory you didn't ask for. The hardware will happily build it anyway.

Reset: decide, don't default

Reset needs a deliberate strategy, because it's where the mismatch between "what the model assumes" and "what the flops actually hold at power-up" lives. The choice here is a synchronous, active-high reset. It matches the convention the Wishbone bus uses (we'll meet it in Part 5) and it keeps timing analysis simple: reset is just another input to the logic in front of each flop.

The alternative is asynchronous reset, where the flop has a dedicated reset pin that acts immediately. That costs a bigger flop cell, and it adds recovery and removal timing checks around the reset release. The usual production recipe is to assert asynchronously and release synchronously, through a small synchronizer. Both styles are legitimate; I'll measure them against each other on a real cell library in Part 7.

The more interesting question is which flops need a reset at all. The rule I use: reset what's architecturally visible, and don't reset what's always overwritten before it's read. The state machine, PC, accumulator, flag and retire pulse are visible, so they reset. The instruction register is written in the LATCH clock before anything reads it, so it doesn't. The memory has no reset either, which is not a choice: a generated SRAM macro has no reset, so software must initialize it.

Reset the state you can see. Don't pay for resetting the state you always overwrite.
A bare circuit board with gold pads and an empty chip footprint
Every flop with a reset pin is a bigger footprint than one without. On a chip, like on this board, area is a budget you spend on purpose.

Lint is a gate, not a suggestion

The command is one line, and its -Wall flag turns on the style checks, not only the correctness ones.

text
1+ verilator --lint-only -Wall --top-module acc8_cpu rtl/acc8_isa_pkg.sv rtl/acc8_mem.sv rtl/acc8_core.sv rtl/acc8_cpu.sv
2%Warning-UNUSEDPARAM: rtl/acc8_isa_pkg.sv:11:26: Parameter is not used: 'OP_HLT'
3                                               : ... note: In instance 'acc8_cpu.u_core'
4   11 |   localparam logic [3:0] OP_HLT = 4'hF;
5      |                          ^~~~~~
6%Error: Exiting due to 1 warning(s)
7exit=1

My first run was not clean. The package defines OP_HLT, but my decode never referred to it, because I'd let a default arm catch the halt instruction implicitly. Lint noticed a constant nobody used. That's a decode that works by accident rather than by statement, so I gave halt its own explicit arm and kept a separate default for the reserved opcodes.

text
1+ verilator --lint-only -Wall --top-module acc8_cpu rtl/acc8_isa_pkg.sv rtl/acc8_mem.sv rtl/acc8_core.sv rtl/acc8_cpu.sv
2- V e r i l a t i o n   R e p o r t: Verilator 5.052 2026-09-05 rev vUNKNOWN-built20260905
3- Verilator: Built from 0.088 MB sources in 5 modules, into 0.051 MB in 3 C++ files needing 0.000 MB
4- Verilator: Walltime 0.025 s (elab=0.005, cvt=0.010, bld=0.000); cpu 0.012 s on 1 threads; allocated 11.188 MB
5exit=0

Clean, with an exit code of zero, in a few hundredths of a second of wall time.

0.025
seconds of wall time Verilator reports for linting the whole design, which is why there is no excuse to skip it

"If lint is noisy, fix the noise. Don't mute the linter."

Lint proves nothing about correctness. What it does is remove whole classes of mistakes (latches, width mismatches, undriven and unused signals, multiple drivers) so that your testbench time goes to the bugs only a testbench can find. Make it a gate in CI and treat warnings as errors from day one, because adding strictness to a codebase later is a miserable job.

Part 3 Checklist 0/6

Next, in Part 4, we plug this RTL into a self-checking Verilator testbench that compares every register after every instruction against the Python model. Then we attack the testbench itself with sixteen deliberate bugs.

How was this article?

Share

Link copied to clipboard!

You Might Also Like

Lee Foropoulos

Lee Foropoulos

Business Development Lead at Lookatmedia, fractional executive, and founder of gotHABITS.

🔔

Never Miss a Post

Get notified when new articles are published. No email required.

You will see a banner on the site when a new post is published, plus a browser notification if you allow it.

Browser notifications only. No spam, no email.

0 / 0