Skip to content
systemcoding.dev
Hardware

What Synthesis, Place and Route and Bitstreams Actually Are

Understand the three stages that turn Verilog into an FPGA bitstream: synthesis to LUTs, place and route onto the fabric, and the configuration bits.

7 min read
Summarize in AI
Flat illustration of logic gates wired into a small circuit, with the GNU, SparkFun and Haskell logos.

A compiler turns source into machine code that a processor fetches and runs. An FPGA flow does something that sounds similar and is quite different. It turns a description of a circuit into the configuration of a chip full of tiny programmable parts, so the chip becomes that circuit. This post explains the three stages, synthesis, place and route, and the bitstream, with small examples of what each produces, for readers who have used the tools and want to know what they actually do. Examples use the open Yosys 0.40 and nextpnr 0.7 on an iCE40, though the stages are the same in every vendor's tools.

The thing being programmed

An FPGA is built from a few repeated resources. The main one is the logic cell or slice: a lookup table, a flip-flop and some carry logic. A lookup table, or LUT, is a tiny memory addressed by its inputs. A four-input LUT holds 16 bits, one for each combination of inputs, and returns the stored bit. Storing the right 16 bits makes it any function of four inputs: an AND, an XOR, a majority vote. Everything else on the chip is wiring: long and short wires and a grid of programmable switches that connect any logic cell's output to many others' inputs. Around the edges are I/O cells connecting wires to pins, and in the body are block RAMs, multipliers and clock managers.

Nothing here is an instruction set. There is no program counter. "Programming" an FPGA means writing the contents of every LUT, every flip-flop setting and every wiring switch.

Stage 1: synthesis

Synthesis answers the question: which logic does this design need? It reads your Verilog and produces a netlist of the chip's building blocks.

Take a simple function and see what comes out:

majority.vverilog
module majority (
    input  wire a,
    input  wire b,
    input  wire c,
    output wire y
);
    assign y = (a & b) | (a & c) | (b & c);
endmodule

Yosys parses this into an expression, optimises it, and maps it to a lookup table. With three inputs, one four-input LUT suffices, and the tool computes the table. The majority function is 1 when at least two inputs are 1, which for inputs ordered c b a gives the truth table 0,0,0,1,0,1,1,1 for indices 0 to 7. Run it and ask Yosys to write the result as Verilog:

Shell
yosys -p "read_verilog majority.v; synth_ice40 -top majority; write_verilog -noattr majority_syn.v"

The written netlist contains one SB_LUT4 instance with a parameter holding the table:

majority_syn.vverilog
module majority(a, b, c, y);
  input a;
  input b;
  input c;
  output y;
  SB_LUT4 #(
    .LUT_INIT(16'hE8E8)
  ) _0_ (
    .I0(a),
    .I1(b),
    .I2(c),
    .I3(1'h0),
    .O(y)
  );
endmodule

The 16-bit LUT_INIT value is the table. Bit number n of it is the output for the input combination n, where I0 is the lowest bit of n. For a, b, c on I0, I1, I2 and I3 tied to 0, the entries for indices 0 to 7 are 0,0,0,1,0,1,1,1, with the same pattern repeated for indices 8 to 15 because I3 is 0 and unused. Reading the bits from index 15 down to 0 gives 1110 1000 1110 1000, which is E8E8. The exact netlist text and instance name from a given Yosys version may differ, but the table value is determined by the function and the input order.

Synthesis does three jobs in this example: it optimises the logic, maps it to the chip's cells, and computes cell contents. It does not decide where anything goes. The netlist says what cells and how they connect, not where they sit. For sequential logic it also maps registers to flip-flops, and it maps memories to block RAM, as the memory post in this cluster describes.

Stage 2: place and route

The netlist is an abstract graph. The chip is a physical grid. Placement assigns every cell in the netlist to a particular logic cell, I/O cell or block on the chip. Routing chooses the wires and switches that connect the placed cells' outputs to their destinations.

Both matter for speed, because signals travel through wires and wires take time. Two cells that talk to each other should sit near each other, and a signal that fans out to many places needs a path to each. A placer treats this as an optimisation: minimise total wire length, subject to the constraint that critical paths stay short. The router then has to find non-conflicting paths. Two signals cannot use the same wire, so routing resembles a very large puzzle of drawing lines without crossing them, solved by negotiation: signals claim wires, conflicts raise the price, and they re-route until none collide.

Constraints enter here. The pin file fixes the I/O cells for the ports, since they have physical meaning. The clock frequency tells the tools which paths are critical. You can see the choices in the log:

Text
Info: Placed 2 cells based on constraints.
Info: Checksum: 0x6e8a1c4f
Info: Routing..
Info: Setting up routing queue.
Info: Routing 31 arcs.
Info: Router1 time 0.01s
Info: Checksum: 0x2b31d7a0

The numbers are illustrative of the format. After routing, the tool measures the delay of every path and prints the maximum frequency, which is the timing result.

Place and route is where a design can fail even though the logic is correct. A design with too many cells does not fit. A design with a long path between two registers meets logic but not timing. The remedy for both is a change in the design, not a different tool setting, because the tools can only arrange what you gave them.

Stage 3: the bitstream

When placement and routing are done, every resource's setting is known: which LUT holds which table, which flip-flop is enabled, which switch connects which wires. The bitstream is the file that lists those settings in the order the chip's configuration logic expects. The chip has a configuration memory, a large array of bits, and loading the bitstream fills it. In most FPGAs that memory is SRAM, so it is volatile, and the chip reads its bitstream from a flash chip at power-up. Some families such as iCE40 UP5K have a small non-volatile memory too, but the usual pattern holds.

The open flows write the configuration in two steps. nextpnr writes a text description, and a packer converts it. In IceStorm's text format, each tile has a section, and a LUT's contents appear as bits in that tile. Here is the shape of one line from an .asc file:

Text
.logic_tile 12 7
00000000000000000000000000000000000000000000
...

A real section has sixteen rows of 54 bits for a logic tile, each bit a configuration cell whose meaning IceStorm documents. icepack turns those rows into the compact binary form with a header and checksums, ready to send. The key point is that there is no code in a bitstream, only configuration data.

Why the stages are separate

Each stage has different inputs and a different kind of difficulty. Synthesis works on logic, with no knowledge of where anything will sit. Place and route work on geometry. The bitstream stage works on a fixed documented format. Separating them means each can be improved or replaced on its own. It also explains where to look when something goes wrong.

SymptomLikely stageWhere to look
Unexpected logic, latch, wrong cell countSynthesisYosys log and stat
Does not fit, unplaced cell, bad pinPlacenextpnr utilisation and constraint messages
Timing fail, long critical pathPlace and routenextpnr timing report
Bitstream rejected or board does not configurePack and programLoader output, cdone state

Compared with software compilation

The analogy to a compiler helps up to a point and misleads beyond it. Synthesis is like compilation to an intermediate form: it parses and optimises. Place and route has no software equivalent, as it deals with physical space, which is why it can take much longer than synthesis and is why results vary with random seeds. The bitstream is the closest to a binary, but it is configuration data for a physical structure, not instructions.

One consequence is that timing is a property of the whole build. In software, the same code runs at the speed of the processor. In an FPGA, the same Verilog can run at different maximum clock frequencies depending on where the tools placed it, which is why the report gives a frequency and why timing closure is a design task.

Also inToolchains
Share

Keep reading

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.