Finding a Latch That Got Into Your Design
Section 5.2 explained why incomplete combinational blocks infer transparent latches. This article provides practical techniques to locate and eliminate unintended latches in large RTL modules.
Reading Synthesis Latch Warnings
Synthesis tools report unintended transparent latches through compiler warnings. The warning message specifies the affected variable and the exact source code line:
Warning: Inferring latch for variable 'grant' in always block at
arbiter.v line 47. Signal 'grant' is not assigned in all
branches of the conditional statement.
Always inspect the exact line referenced in the warning message. Do not waste engineering time scanning unrelated source code. Navigate directly to line 47 and determine which execution paths fail to assign the variable.
Diagnostic Code Review Checklist
Review the flagged combinational always block against two common coding patterns:
Pattern 1: Missing Else Branch
An if statement without an else branch preserves previous data when the condition evaluates to false:
always @(*) begin
if (req)
grant = 1'b1;
// Missing: grant is not assigned when req is 0
end
Pattern 2: Incomplete Case Statement
A case statement without complete case coverage infers a latch for unlisted conditions:
always @(*) begin
case (state)
IDLE: grant = 1'b0;
ACTIVE: grant = 1'b1;
// Missing: unhandled states and unused binary encodings
endcase
end
To eliminate inferred latches, add a default assignment at the beginning of the combinational block:
always @(*) begin
grant = 1'b0; // Default assignment ensures all execution paths assign grant
case (state)
IDLE: grant = 1'b0;
ACTIVE: grant = 1'b1;
endcase
end
The Multi-Signal Trap
Engineers frequently introduce latches when an always block assigns multiple output signals.
A default assignment for one variable does not protect other unassigned variables in the same block:
always @(*) begin
result = 8'h00; // Default provided: result will not infer a latch
// valid has no default assignment: infers a latch
if (op_valid) begin
result = a + b;
valid = 1'b1;
end
end
In the example above, result evaluates on every branch.
However, valid receives an assignment only when op_valid is high.
The synthesis compiler will issue a latch warning specifically for valid.
Provide explicit default assignments for every variable modified inside the combinational block.
Verifying the Resolution
After modifying the source code, run a linter or resynthesize the design. Verify that the compiler removes the specific latch warning for the target variable. Confirm that default assignments appear at the top of the block, outside nested conditional statements.
Section 7.6 described operand isolation, which uses intentional transparent latches for low-power gating. Intentional latches must be documented and formally waived in synthesis constraint scripts. Design reviews must differentiate between approved, waived latches and unreviewed accidental latches.
Practice Exercise
A synthesis tool reports Warning: Inferring latch for variable 'busy' in always block at controller.v line 112.
Inspection of line 112 reveals a case statement with four listed states.
Each of the four states assigns busy, but there is no default clause.
The state register has a width of 3 bits.
Explain why the compiler inferred a latch.
Solution
A 3-bit register supports $2^3 = 8$ distinct binary combinations.
The case statement explicitly defines only four states.
The remaining four binary combinations represent unhandled states.
Because the block lacks a default clause, the synthesizer preserves previous values for these four states.
This data-retention behavior infers a hardware latch for busy.
To resolve the warning, add a default clause or a top-level default assignment.
Synthesis compilers issue clear warnings with variable names and file locations when latches are inferred. Designers prevent latch inference by adding default assignments for all modified variables. Always rerun linting and synthesis tools to confirm warning elimination. The next article analyzes reset domain issues that emerge during multi-module integration.