RTL Design / Module 4: Combinational Design from Scratch
Lesson 4.4

Incomplete case / sensitivity → latches

You built muxes, adders, and ALU slices — all combinational. But one missing else, one forgotten default, or one legacy always @(a) sensitivity list and synthesis quietly inserts a latch. This lesson teaches you to see the pattern, fix it with default assignments, and let lint catch it before tapeout.

Core idea

Combinational logic must produce a defined output for every input combination, on every evaluation. If the tool cannot prove that, it keeps the old value — and that "memory" is a latch.

1

How a latch gets inferred

Latch inference from incomplete RTL

A latch is not magic — it is the tool preserving a signal when your RTL forgot to drive it.

RTL patternWhat synthesis seesResult
always @(*) with full branchesPure combinational cloud✅ Gates only
case missing defaultOutput holds when sel hits uncovered value❌ Latch on out
if without final elseOutput undefined for some input combos❌ Latch on out
always @(a) — partial sensitivityRe-evaluates only when a changes❌ Latch + sim/synth mismatch
Default assign then overrideEvery path assigns out✅ Latch-free
Analogy

Think of combinational logic as a vending machine: every coin combination must dispense something. An incomplete case is a machine that sometimes keeps the last snack in the slot because you never told it what to do — that "keeping" is the latch.

2

Incomplete case — bad vs good

The most common latch bug in student RTL: a case that covers the opcodes you tested in sim, but not all bit patterns synthesis must handle.

bad_case_latch.v
// BAD — latch when sel = 2'b11
module bad_mux3 (
  input  wire [1:0] sel,
  input  wire [7:0] a, b, c,
  output reg  [7:0] out
);
  always @(*) begin
    case (sel)
      2'b00: out = a;
      2'b01: out = b;
      2'b10: out = c;
      // sel=11: out not assigned → latch inferred
    endcase
  end
endmodule
good_case_default.v
// GOOD — explicit default branch
module good_mux3 (
  input  wire [1:0] sel,
  input  wire [7:0] a, b, c,
  output reg  [7:0] out
);
  always @(*) begin
    case (sel)
      2'b00:   out = a;
      2'b01:   out = b;
      2'b10:   out = c;
      default: out = 8'h00;  // safe known value
    endcase
  end
endmodule
good_default_assign.v
// GOOD — default assignment pattern (preferred in large case blocks)
module good_mux3b (
  input  wire [1:0] sel,
  input  wire [7:0] a, b, c,
  output reg  [7:0] out
);
  always @(*) begin
    out = 8'h00;           // default FIRST — latch impossible
    case (sel)
      2'b00: out = a;
      2'b01: out = b;
      2'b10: out = c;
    endcase
  end
endmodule
Trap

Assigning inside only some branches of an if/else if chain without a final else creates the same latch. if (en) out = a; with no else is a classic interview question — and a real silicon bug.

3

Incomplete if/else chains

Priority encoders and conditional muxes often use if/else if. Without a covering else, the last signal driven "sticks."

bad_if_chain.v
// BAD — latch when req = 4'b0000
always @(*) begin
  if      (req[0]) grant = 4'b0001;
  else if (req[1]) grant = 4'b0010;
  else if (req[2]) grant = 4'b0100;
  else if (req[3]) grant = 4'b1000;
  // no else — grant holds when req=0
end
good_if_chain.v
// GOOD — default assignment covers all inputs
always @(*) begin
  grant = 4'b0000;                    // no request → no grant
  if      (req[0]) grant = 4'b0001;
  else if (req[1]) grant = 4'b0010;
  else if (req[2]) grant = 4'b0100;
  else if (req[3]) grant = 4'b1000;
end
🎯

Default-at-top pattern

Assign every output to a safe value first, then override in branches. Works for case, if, and FSM next-state logic.

📋

Named default branch

Use default: in case or final else in if chains. Document whether default is error, idle, or don't-care.

4

Missing sensitivity — the legacy always @(a) bug

Before always @(*), engineers hand-wrote sensitivity lists. Miss one input and simulation lies while synthesis builds different hardware.

Golden rule: Use always @(*) or always_comb (SystemVerilog) for all combinational blocks. Never hand-pick signals unless you are writing a testbench.

bad_sensitivity.v
// BAD — only re-evaluates when 'a' changes; b and sel ignored in sensitivity
always @(a) begin
  if (sel) out = a + b;
  else     out = a - b;
end
// Simulation: out stuck until 'a' toggles even if sel/b change
// Synthesis:  may still infer combo logic OR latch depending on tool
good_sensitivity.v
// GOOD — automatic full sensitivity
always @(*) begin
  if (sel) out = a + b;
  else     out = a - b;
end

// SystemVerilog equivalent:
// always_comb begin
//   if (sel) out = a + b;
//   else     out = a - b;
// end
Sensitivity styleSim behaviorSynth behaviorVerdict
always @(a)Misses updates when b/sel changeTool-dependent; often warns❌ Never in RTL
always @(a or b or sel)Correct if list is completeUsually OK⚠️ Fragile — easy to forget new signal
always @(*)Full automatic sensitivityCombinational intent clear✅ Default choice
5

full_case / parallel_case — myths, lightly

Verilog pragmas // synopsys full_case and // synopsys parallel_case tell the synthesizer "trust me, this case is complete / non-overlapping." They do not fix incomplete RTL — they silence warnings.

Industry reality

full_case says all input values are covered. If you lie, synthesis may optimize away "unreachable" logic that simulation still hits.

parallel_case says branches don't overlap. Wrong pragma → priority logic you didn't intend.

Modern teams prefer provably full case with default over pragmas. Let formal/lint prove coverage instead of commenting your way past warnings.

pragma_trap.v
// DANGEROUS — pragma hides latch warning but logic is still incomplete
always @(*) begin
  case (sel) // synopsys full_case
    2'b00: out = a;
    2'b01: out = b;
    // 2'b10, 2'b11 uncovered — latch may still exist!
  endcase
end
// Fix the RTL; don't silence the linter.
6

How lint tools catch latches

Run lint on every commit. Latch inference is a high-severity finding because latches break timing closure and often indicate a logic bug.

ToolTypical warningWhat it means
SpyGlass / VC LintLatch inferred / INFERRED_LATCHCombo block doesn't assign all outputs in all paths
Verilator lintCOMBLOOP / incomplete assignmentSignal may retain value — check always block
Design CompilerLINT-1 inferred latch on regChange to default-assign pattern or add branch
Vivado[Synth 8-327] latch inferredSame root cause — incomplete assignment
Write RTL → Run lint → Fix latch warnings → Re-lint until clean → Synthesize

Pro tip: Treat "latch inferred" as a blocking issue in code review — same severity as multiply-driven nets. Zero tolerance in combinational datapath modules.

7

Mini-labs — find and fix the latch

Paste each snippet into the simulator. Synthesis-oriented lint may not run in-browser, but you can reason about which signals are incomplete.

lab1_decoder.v
// LAB 1 — Fix the latch in this 2-to-4 decoder
module lab1_decoder (
  input  wire [1:0] addr,
  output reg  [3:0] dec
);
  always @(*) begin
    case (addr)
      2'b00: dec = 4'b0001;
      2'b01: dec = 4'b0010;
      2'b10: dec = 4'b0100;
      // TODO: add missing branch or default
    endcase
  end
endmodule
// Fix: default dec = 4'b0000; OR 2'b11: dec = 4'b1000;
lab2_alu_slice.v
// LAB 2 — ALU op decode with incomplete if chain
module lab2_alu_slice (
  input  wire [1:0] op,
  input  wire [7:0] a, b,
  output reg  [7:0] y
);
  always @(*) begin
    if (op == 2'b00)      y = a + b;
    else if (op == 2'b01) y = a - b;
    else if (op == 2'b10) y = a & b;
    // op==11: y not assigned → latch
  end
endmodule
// Fix: y = 8'h00; at top, or else y = a | b;
lab3_fixed.v
// LAB 3 — Reference solution pattern for lab2
localparam OP_ADD = 2'b00, OP_SUB = 2'b01, OP_AND = 2'b10, OP_OR = 2'b11;

always @(*) begin
  y = 8'h00;
  case (op)
    OP_ADD: y = a + b;
    OP_SUB: y = a - b;
    OP_AND: y = a & b;
    OP_OR:  y = a | b;
    default: y = 8'h00;
  endcase
end
▶ Fix latches in the simulator
8

Latch-free combinational checklist

  • Every combo block uses always @(*) — never partial sensitivity lists
  • Every reg output in combo logic has a value on every path
  • Default assignment at top of block OR default/else on every branch structure
  • No full_case pragma as a substitute for real coverage
  • Lint run shows zero inferred-latch warnings before review
  • Simulation and synthesis see the same combinational behavior
  • FSM next-state logic uses the same default-assign discipline

🎯 What to remember

  • Latches appear when combinational logic fails to assign every output for every input.
  • Default-at-top (out = 0; then override) is the safest latch-prevention pattern.
  • always @(*) fixes sensitivity; it does not fix incomplete branches — you need both.
  • Pragmas silence warnings; they don't fix hardware. Write full case instead.
  • Next up: Lab 4.5 integrates mux + ALU + decode into one clean datapath slice.
Advertisement