Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • Logic Synthesis Glossary
  • Logic Synthesis Cheatsheet
  • Synthesis Foundations14
    • Synthesis Flow Overview
    • Synthesizable RTL and Inference
      • Combinational Blocks Infer Logic
      • Priority Chains versus Parallel Selects
      • Latch Inference from Incomplete Assignment
      • Flops, Tri-States and Unrolled Loops
      • What Is Not Synthesizable
    • Reading Netlists and Reports
  • Logic Optimisation and Mapping20
  • Constraints and Timing15
  • Sequential, FSM and Memory19
  • Datapath Synthesis14
  • Area, Power and Test14
  • Verification, ECO and Handoff15
  • Flows and Debugging15
  • Interview and Judgment11
Loading lesson

‹Synthesizable RTL and Inference
  1. Topics
  2. Logic Synthesis
  3. Synthesis Foundations
  4. Synthesizable RTL and Inference
  5. Latch Inference from Incomplete Assignment

Part 1 · Synthesis Foundations · Intermediate

Latch Inference from Incomplete Assignment

Incomplete assignment infers a latch, and default assignment removes it.

On this page

    How a latch is inferred

    A latch holds the old value while its enable is low. A synthesis tool infers one exactly when some path through a combinational block skips an output.

    The script below reads that shape: an if with no else. It pins exactly one $dlatch with no $dff.

    yosys
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    read_verilog <<EOV
    module latch_top (
      input wire d,
      input wire en,
      output reg q
    );
      always @* begin
        if (en)
          q = d;
      end
    endmodule
    EOV
    hierarchy -check -top latch_top
    proc
    select -assert-count 1 t:$dlatch
    select -assert-none t:$dff
    log PASS: missing else branch infers one latch with no flop

    Code shape

    Skipped path

    Cell

    if without else

    Condition low

    $dlatch

    case without default, values missing

    Uncovered values

    $dlatch

    Default assigned before the branch

    None

    $mux

    The one-line fixes

    Each fix makes every path assign the output. The latch disappears and a multiplexer takes its place.

    • Assign a default value before the if or case.

    • Add the missing else branch.

    • Add a default item to the case.

    Testbench

    The testbench below drives a latch and a mux with the same inputs. The latch holds its value when the enable drops, while the mux follows its input.

    latch_demo.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    module latch_demo (
      input wire d,
      input wire en,
      output reg q
    );
      always @* begin
        if (en)
          q = d;
      end
    endmodule
    
    module mux_ref (
      input wire d,
      input wire en,
      output reg y
    );
      always @* begin
        if (en)
          y = d;
        else
          y = 1'b0;
      end
    endmodule
    
    module tb_latch_hold;
      reg d;
      reg en;
      wire q_latch;
      wire y_mux;
      integer errors;
      latch_demo l (.d(d), .en(en), .q(q_latch));
      mux_ref m (.d(d), .en(en), .y(y_mux));
      initial begin
        errors = 0;
        d = 1; en = 1; #1;
        if (q_latch !== 1'b1) errors = errors + 1;
        if (y_mux !== 1'b1) errors = errors + 1;
        d = 0; en = 0; #1;
        if (q_latch !== 1'b1) errors = errors + 1;
        if (y_mux !== 1'b0) errors = errors + 1;
        if (errors == 0) $display("PASS: latch holds last value while mux follows input");
        else $display("FAIL: %0d mismatches", errors);
        $finish;
      end
    endmodule

    Common mistakes

    Common pitfall

    An unintended latch rarely announces itself in simulation. It looks like a signal that keeps its old value after its inputs changed, and the netlist shows $dlatch where a $mux was expected.

    Interview

    Likely probes: the latch condition and its fixes.

    • A combinational path that skips an output infers a latch.

    • A default first, an else, or a default item each close the gap.

    • The script proves one $dlatch, and the testbench shows the hold behavior.

    Check yourself An if without an else drives an 8-bit bus in a combinational block. How many latches does the tool infer?

    Eight, one $dlatch per bit. Each bit holds its own old value on the skipped path.

    Check yourself The same block gains q = 0 before the if. What changes in the netlist?

    Every path now assigns the output. The latches disappear and a multiplexer takes their place.

    Related topics

    • Combinational Blocks Infer Logic

    • Simulation Synthesis Mismatch

    • Latch Inference

    Previous

    10 / 139

    Next: Flops, Tri-States and Unrolled Loops

    Up next

    Up nextFlops, Tri-States and Unrolled Loops

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Combinational Blocks Infer Logic
    • What Is Not Synthesizable