Context
Buterin shows that hardware design, like software, compiles from high-level languages down to lower-level descriptions. The further below Verilog you go, the more the tools need to know about a specific fab process: the netlist is already tied to a particular standard-cell library, DEF describes wire coordinates, and GDS lists the polygons of every component.
That information comes from the fab's process design kit (PDK), which also contains the rules for design rule checking (DRC). According to the author, frontier fabs keep their PDKs and tools proprietary behind non-disclosure agreements, while open processes pay a significant price in performance.
Exercise 1: an 8-bit register
The module acts on the rising clock edge. When rst_n is low the register is set to 1; otherwise it stores q plus q shifted left by one bit (q + 2q), so the value is multiplied by 3 and only the low 8 bits are kept. This is a simplified version of Buterin's example without the Tiny Tapeout I/O ports.
`default_nettype none
module mul3_reg (
input wire clk,
input wire rst_n, // active-low synchronous reset
output reg [7:0] q // 8-bit state register
);
always @(posedge clk) begin
if (!rst_n)
q <= 8'd1; // start value
else
q <= q + (q << 1); // q * 3, only the low 8 bits are kept
end
endmodule
Exercise 2: a testbench for simulation
The testbench generates a clock, releases the reset and prints eight consecutive values.
`timescale 1ns/1ps
module tb;
reg clk = 0, rst_n = 0;
wire [7:0] q;
mul3_reg dut (.clk(clk), .rst_n(rst_n), .q(q));
always #5 clk = ~clk;
initial begin
@(posedge clk); #1 rst_n = 1;
repeat (7) begin
$display("q = %0d", q);
@(posedge clk); #1;
end
$display("q = %0d", q);
$finish;
end
endmodule
Exercise 3: simulation and Yosys synthesis
The first line simulates with Icarus Verilog. The second runs Yosys's generic synth command to turn the design into logic gates, and the third prints the statistics.
iverilog -o sim mul3_reg.v tb.v && vvp sim
yosys -p "read_verilog mul3_reg.v; synth -top mul3_reg; stat" > yosys.log
grep -A 22 "^3. Printing statistics" yosys.logExpected result
The code was tested with Icarus Verilog and Yosys 0.52. The values go 1, 3, 9, 27, 81, 243, then 729 mod 256 = 217 and 651 mod 256 = 139. A detail worth noticing: Yosys created 7 flip-flops ($_SDFF_PN0_), not 8. The lowest bit becomes 1 after reset and, because an odd number times 3 is still odd, it stays 1 forever, so Yosys optimizes it into a constant.
Cell counts may differ between Yosys versions.
q = 1
q = 3
q = 9
q = 27
q = 81
q = 243
q = 217
q = 139
Number of cells: 41
$_ANDNOT_ 9
$_NAND_ 5
$_NOR_ 4
$_NOT_ 1
$_ORNOT_ 1
$_OR_ 2
$_SDFF_PN0_ 7
$_XNOR_ 7
$_XOR_ 5Limitations
This exercise covers only logic synthesis: here Yosys maps to its own generic gates, not fab-specific cells. A real chip also needs mapping to a PDK, placement and routing (for example with OpenROAD), DRC and GDS generation. As Buterin notes, even with open processes the lithography corrections are done only by the fab.


