Draft preview. Lessons are being written and reviewed.

Digital Design / Module 11: Designing for silicon

60. What synthesis does to your code

Picture the gates your code becomes.

Lecture coming soon

See it move

The idea

Synthesis turns your RTL into a netlist: real gates and flops selected from a technology library. Picture the hardware while writing code, because synthesis produces what you described, whether or not that is what you meant.

The steps

  • Elaborate: read the RTL and resolve parameters and generate blocks.
  • Translate: turn it into generic logic.
  • Optimise: simplify logic, share resources, and choose structures.
  • Map: select library cells that meet your timing constraints with least area and power.

Timing constraints drive every decision. The same RTL can map to a small, slow adder, or a large, fast one.

What doesn't synthesize

  • # delays are ignored, as timing comes from the cells.
  • initial blocks are generally not supported for ASICs, though some FPGAs honour them.
  • Testbench features such as $display and file access are ignored or rejected.

Simulation and synthesis can disagree

Your RTL simulation and the resulting gates can behave differently. Common causes:

  • Incomplete sensitivity lists: simulation doesn't react, but gates always do.
  • : if (x) takes the else path in simulation, while real gates hold a definite 0 or 1.
  • Blocking and non-blocking mix-ups.
  • (casez and x assignments) that the tool resolved in its own way.

Gate-level simulation and equivalence checking exist to catch these. Equivalence checking formally proves that the netlist matches the RTL.

Reading the reports

Always read the output: check for inferred latches, removed logic, and unconnected pins. Compare area by block, and check timing. A warning that a signal was optimised away can mean that you forgot to use it.

Common mistake

Writing clever RTL to save gates, in a way the tool would have done anyway, and making the code harder to read. Clear code usually gives equal or better results. Save your cleverness for architecture: that's where the real gains are.

Key ideas

  • RTL maps to library cells using constraints.
  • Initial blocks and delays usually aren't synthesized for ASICs.
  • Simulation and gate-level results can mismatch.

Your exercise

Compare gate counts for two styles of the same block.

Interview questions

coreWhy might simulation and synthesis disagree?

basicWhat are the main steps a synthesis tool goes through to turn RTL into a netlist?

basicWhat hardware does each of these three lines become?

assign y = s ? a : b;
always @(posedge clk) q1 <= d;
always @(*) if (en) q2 = d;

coreThis counter counts 0, 1, 2 in RTL simulation, but gate-level simulation shows X forever. Why?

module cnt (input clk, output reg [3:0] q);
  initial q = 4'd0;
  always @(posedge clk) q <= q + 4'd1;
endmodule

coreThis block is meant to be an AND gate. In RTL simulation, setting a = 1 and then b = 1 leaves y at 0. What will the synthesized gate do, and why do they differ?

module and_bad (input a, b, output reg y);
  always @(a) y = a & b;
endmodule

coreIn this mux, sel is X because it comes from a flop that was never reset. What does RTL simulation show for a = 1, b = 0, and what does real hardware do?

always @(*) begin
  if (sel) y = a;
  else     y = b;
end

coreThe same 32-bit a + b can become a small adder in one design and a much larger one in another. Why?

advancedHow many adders does this code need? How might synthesis reduce that, and what does it cost?

always @(*)
  if (sel) y = a + b;
  else     y = c + d;

advancedA synthesis report says a whole block of logic was removed, and the area is much smaller than expected. What do you check?

Practise these 9 questions with animations