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

  • RTL Foundations36
  • Combinational Design25
    • Combinational Timing Overview
    • Muxes, Decoders and Encoders
    • Arithmetic Blocks
    • Comparators and Shifters
    • Tri-State and Shared Buses
    • Latch Inference
      • Why Accidental Latches Happen
      • The Complete-Assignment Pattern
      • Intentional Latches
    • Arithmetic Datapaths
  • Sequential Design27
  • FSM & Control27
  • Timing & Clocking39
  • Reset & CDC34
  • Memory & Buses57
  • Advanced RTL28
  • Senior & Interview76
  • Glossary and Notation
Loading lesson

‹Combinational Design
  1. Topics
  2. RTL Design
  3. Combinational Design
  4. Latch Inference

Part 2 · Combinational · Intermediate

Latch Inference

A missing assignment infers a latch: the four causes, the default-first fix, and deliberate uses.

  • 3topics
  • 3lessons

Topics in this section

  1. 1Why Accidental Latches Happen1 lesson
  2. 2The Complete-Assignment Pattern1 lesson
  3. 3Intentional Latches1 lesson
On this page

    Combinational logic must assign every output on every path. A missed path holds its old value, so synthesis builds a latch.

    An unassigned path forces holding a value, which synthesis implements as a latch.
    The causal chain behind every accidental latch.

    Lessons in this topic

    3 lessons, about 13 min

    1. 1Why Accidental Latches HappenYou can spot the four classic causes of an accidental latch and explain why holding a value needs storage.5 min
    2. 2The Complete-Assignment PatternYou can apply the default-then-override pattern, choose a safe default, and avoid fixes that re-infer the latch.3 min
    3. 3Intentional LatchesYou can explain how a latch-based clock gate avoids glitches, and list the rules for writing an intentional latch.5 min
    Check yourself Is a latch always a bug?

    No. Latches are legitimate storage elements and are used on purpose in clock-gating cells and some high-speed designs. The bug is an unintended latch, which is why intentional ones are written with always_latch and a comment, and everything else is checked to be latch-free.

    Interview

    “What is a latch, how does it get inferred, and how do you avoid it?” is among the most common RTL questions. This topic gives you the complete answer plus evidence.

    Revision sheet

    The whole topic on one page, taken from each lesson's Remember box. Read it before an interview, or print it.

    Why Accidental Latches Happen

    • Any path that leaves an output unassigned makes the output hold, and holding needs a latch.

    • Four causes: if without else, a case that misses a value, an output assigned on fewer paths than another, and a conditional assignment in a loop.

    • always_comb turns the latch into a diagnostic; plain always @(*) does not.

    Rule of thumb: if a path does not assign the output, the hardware must remember it.

    The Complete-Assignment Pattern

    • Assign every output before any conditional, then let branches override.

    • Use blocking = in always_comb and nonblocking <= in always_ff, and do not mix them.

    • For next-state logic the natural default is next = state.

    Rule of thumb: treat any latch warning as a failure, and never write y = y; to silence it.

    Intentional Latches

    • A latch is transparent while its enable is active and holds otherwise. A flip-flop is two latches that are never open together.

    • The gate latch is open only while clk is low, so en cannot change the AND output while clk is high.

    • Write intentional latches with always_latch, comment why, and review each one.

    Rule of thumb: in real designs use the library's clock-gating cell rather than a hand-built latch.

    Practise it

    • Mini project: a 32-bit leading-zero counter and normaliser

    • Practice question: A level-sensitive latch: when it is risky and how to code it safely

    • Practice question: A safe clock-gating cell with a latch-based enable

    • Interview: run a mock interview on this topic

    PreviousNext: Why Accidental Latches Happen

    Up next

    Up nextWhy Accidental Latches Happen

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Combinational Timing Overview
    • Muxes, Decoders and Encoders
    • Arithmetic Blocks