Module 8: RTL Coding for Quality & Synthesis · 8.1 RTL Coding Guidelines & Style

The Sim/Synth Mismatch Checklist

A simulation-synthesis mismatch occurs when a Verilog logic simulator interprets code differently than a hardware synthesis compiler. These defects are dangerous because behavioral testbenches pass cleanly in simulation. Discrepancies appear only after synthesizing physical silicon or programming an FPGA bitstream. Engineers prevent these defects by avoiding ambiguous Verilog syntax constructs:

One ambiguous construct, two legitimate readings, a testbench that passes and hardware that differs
Figure 1: How an ambiguous construct becomes a mismatch

The Complete Prevention Checklist

  1. Avoid casex Constructs (Section 5.3): The casex keyword treats unknown states (x) as wildcards. In simulation, an uninitialized x input matches wildcard branches that physical hardware never executes. Use casez instead, which treats only high-impedance (z) and explicit wildcard tokens (?) as don’t-care conditions.
  2. Eliminate Hand-Written Combinational Sensitivity Lists (Section 5.2): Omitting an input from an explicit sensitivity list prevents the simulator from updating outputs when that input transitions. Synthesis compilers ignore sensitivity lists and infer hardware that responds to all inputs. Always specify always @(*) for combinational logic.
  3. Avoid Synthesis Pragmas: full_case and parallel_case (Section 5.3): Simulators ignore comment pragmas, while synthesis tools optimize logic based on them. If pragma assertions prove false, synthesized gates behave differently than simulated code. Write explicit default branches instead of using compiler pragmas.
  4. Prevent Unintended Latch Inference (Section 5.2): Omitting branch conditions in combinational blocks creates level-sensitive transparent latches. Latches complicate static timing analysis and trigger race conditions. Assign default output values at the beginning of combinational always blocks.
  5. Never Substitute initial Blocks for Reset Logic (Section 5.1): Simulators initialize registers using initial blocks. In ASIC synthesis, compilers ignore initial blocks for sequential logic. Physical hardware powers on in undefined states. Always provide physical reset paths for hardware registers.
  6. Enforce Non-Blocking Assignment Discipline (Section 5.1): Mixing blocking (=) and non-blocking (<=) assignments creates simulation race conditions. Use non-blocking assignments exclusively for sequential registers. Use blocking assignments exclusively for combinational logic blocks.
  7. Prevent Silent Signed-to-Unsigned Coercion (Section 7.2): Mixing signed and unsigned operands forces compilers to evaluate the entire expression as unsigned. Relational comparisons produce incorrect results. Enforce consistent signed declarations across all operands.

Universal Coding Principle

Write RTL source code whose logical interpretation does not depend on specific tool implementations. Prefer unambiguous language constructs over implicit tool assumptions:

  • Use casez instead of casex.
  • Use always @(*) instead of explicit sensitivity lists.
  • Write explicit default branches instead of full_case pragmas.
  • Enforce explicit reset nets instead of initial blocks.

Automated static analysis tools (such as Verilator with --lint-only or Synopsys SpyGlass) flag these patterns before synthesis. Enforce automated linting in continuous integration pipelines to maintain code quality.

Verification Exercise

Analyze the following Verilog code fragments and identify which checklist items they violate:

// Fragment A
always @(state)
    next_state = (state == IDLE) ? ACTIVE : IDLE;

// Fragment B
initial q = 1'b0;
always @(posedge clk) q <= d;
View Solution
  • Fragment A Violates Item 2: The block uses an explicit sensitivity list @(state) for combinational logic. While currently sufficient, subsequent edits that add input signals will introduce simulator update bugs. Replace with always @(*).
  • Fragment B Violates Item 5: The register relies on an initial block for initialization. Synthesis compilers discard initial blocks on ASICs. The register powers on with an indeterminate value. Add an explicit reset signal: if (!rst_n) q <= 1'b0; else q <= d;.

This concludes Section 8.1. Section 8.2 examines synthesis-aware coding, predicting gate-level structures, and controlling resource sharing.

← Reset Strategy Consistency What Synthesis Does With Your RTL →