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

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

Part 2 · Combinational · Intermediate

Intentional Latches

When a latch is the right cell: clock gating, time borrowing, and the discipline that keeps it safe.

On this page

    Why this matters

    A clock gate built as clk & en makes a runt pulse if en changes while clk is high. A latch that is open only while the clock is low fixes it, which is the one place a latch is the right tool.

    After this lesson you can: explain how a latch-based clock gate avoids glitches, and list the rules for writing an intentional latch.

    A latch is a deliberate tool

    A latch is transparent while its enable is active: the output follows the input. When the enable closes, the output holds.

    A flip-flop is two latches back to back that are never transparent together. It samples only at an edge.

    Used on purpose, a single latch is smaller and faster with useful properties. Used by accident, it is a bug.

    Element

    Output follows input when…

    Typical use

    Latch (active-low enable)

    Enable is low (transparent), holds when high

    Clock gating, time borrowing, small storage

    Flip-flop

    Never directly: samples at the clock edge

    Almost all registers

    The classic: a glitch-free clock gate

    Switching a clock off to save power must not truncate or fragment a clock pulse. If the enable changes while the clock is high, gclk = clk & en can produce a runt pulse.

    The fix is a latch that holds the enable stable during the high phase: it is transparent only while the clock is low.

    Each column is one clock edge. Watch en_l against en while en moves mid-cycle.

    • Slot 1: rising edge with en at 0, so no pulse and gclk is 0.

    • Slot 2: falling edge, still quiet; en rises just after, mid low-phase, and the open latch follows it to 1.

    • Slot 3: rising edge finds en_l at 1, so the first pulse starts whole and gclk is 1.

    • Slot 4: falling edge ends the first pulse whole, and gclk is 0.

    • Slot 5: rising edge starts the second pulse whole; en then drops mid high-phase, between two samples, so the picture cannot show it. The closed latch holds en_l at 1 until the clock falls.

    • Slot 6: falling edge ends the pulse at full width; the latch reopens while clk is low and en_l follows en to 0.

    • Slot 7: rising edge with the gate closed, so gclk stays 0.

    A plain AND gate would cut the second pulse short the moment en falls. The latch keeps en_l steady instead, so both pulses stay full width.

    Check yourself In the gate and testbench at the end of this page, the enable drops at t = 17 while the clock is high. Predict the width of the second pulse.

    The latch is transparent only while clk is low. At t = 17 clk is high, so the latch is closed and still holds the enable value 1 captured earlier; the AND output stays high until the clock falls at t = 20. The enable change takes effect only after the next low phase, so there is no runt pulse.

    Clock gating cell: an enable latch, controlled by the clock, feeding an AND gate with the clock.
    The latch holds the enable steady while the clock is high, so in the ideal mechanism, with the enable meeting its setup and hold to the latch, the AND gate does not produce a runt pulse.

    Warning

    This is the ideal functional mechanism. Signoff also needs the gating checks and timing limits covered in Clock gating. In real designs, use the library's integrated clock-gating (ICG) cell rather than a hand-built latch and AND. The library cell is characterized for timing and glitch behaviour, and the clock tree tools understand it. Write the RTL for the enable logic and instantiate or infer the ICG through your flow's approved method.

    Other uses and rules

    Other legitimate uses

    • Time borrowing: a transparent latch lets a slow stage borrow time from the next one, smoothing unbalanced pipelines. This is a specialist, hand-timed technique.

    • Small, wide storage where a latch array is much smaller than flip-flops (for example register files in some processes), with careful timing sign-off.

    Rules for intentional latches

    • Write them with always_latch so the intent is explicit and tools can check it.

    • Comment why a latch is needed.

    • Constrain timing so the flow understands latches (time borrowing, enable-to-output paths).

    • Check that scan test and DFT handle them, since latches often need special treatment.

    • Review each one individually, and treat an unexpected latch count in the synthesis report as a failing check.

    Interview

    Senior-level follow-up: “How does a latch-based clock gate avoid glitches?” Because the latch is closed (opaque) during the clock-high phase, the enable cannot change the AND gate's output while the clock is high.

    Testbench

    This ideal RTL test checks every completed pulse without rounding its width to an integer. Expected pulses rise at 5 and 15 ns and fall at 10 and 20 ns; each width must be 5 ns. Enable drops at 17 ns, so the second pulse must still finish at 20 ns, with no later pulse. The final check requires two starts, two completions and no pending pulse. An initialization X-to-0 transition is ignored only at time zero; later unmatched falling edges are failures.

    icg.sv
    1
    2
    3
    4
    5
    6
    7
    8
    module icg (
      input  logic clk, en,
      output logic gclk
    );
      logic en_l;
      always_latch if (!clk) en_l = en;     // transparent while clk is low, holds while clk is high
      assign gclk = clk & en_l;             // the gated clock
    endmodule
    

    Remember

    • 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.

    How this was checked

    The checker also runs its width predicate on a synthetic short-first, correct-second trace: widths of 2 ns and 5 ns must reject the first pulse even though the last width is correct. This is a checker self-check, not an injected DUT measurement.

    The bounded stimulus shows functional behaviour for this enable sequence only. Library gating setup and hold checks, analog runt-pulse limits and physical signoff remain separate.

    Keep going

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

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

    • Interview: run a mock interview on this topic

    Related topics

    • Clock gating in the timing section

    • Clock enable vs gated clock

    Previous

    56 / 350

    Next: Arithmetic Datapaths

    Up next

    Up nextArithmetic Datapaths

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Why Accidental Latches Happen
    clkenen_lgclk
    The latch holds the enable steady across the high phase