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

AboutRoadmapCareersInternshipsFAQContactPrivacyTerms
Skip to lesson

Course contents

  • RTL Foundations36
  • Combinational Design25
  • Sequential Design27
  • FSM & Control27
  • Timing & Clocking39
    • STA Foundations
    • Setup, Hold and Slack
    • Skew and Variation
    • Timing Exceptions
    • Clock Gating
      • Why Clock Gating Saves Power
      • The ICG Cell
      • Safe RTL Gating Style
      • Enable Quality Rules
      • Latch-Based Gating: Timing and Signoff
    • RTL for Timing
    • Clock Architecture
  • Reset & CDC34
  • Memory & Buses57
  • Advanced RTL28
  • Senior & Interview76
  • Glossary and Notation
Loading lesson

←Clock Gating
  1. Topics
  2. RTL Design
  3. Timing & Clocking
  4. Clock Gating
  5. Safe RTL Gating Style
On this page

    Part 5 of 9, lesson 23 of 39Part 5 of 9/Timing & Clocking/Lesson 23 of 39Intermediate

    Safe RTL Gating Style

    Two equivalent ways to write a gated register and the rules for explicit gates.

    Gating a register is usually one line, if (en) q <= d, and the tool can turn it into a clock gate. A hand-built gate has traps: a synchronous reset on a stopped clock never takes effect, and scan shifting stops without a test enable.

    After this lesson you can: write a gated register as a plain enable, decide when to instantiate the ICG yourself, and follow the rules for an explicit gate.

    Write an enable

    design.sv
    1
    2
    3
    4
    // snippet
    always_ff @(posedge clk or negedge rst_n)
      if (!rst_n)  q <= '0;
      else if (en) q <= d;          // synthesis can replace the enable mux with a clock gate

    This is the recommended default. Plain RTL lets the tool turn shared-enable feedback muxes into clock gates where they pay off, keeping the design synchronous and portable.

    Instantiate the gate

    Use this when you need control over the gating structure (a power domain, a hand-built clock tree) or when the tool cannot infer it.

    The same register written two ways. Style A keeps the clock on every edge and recirculates q through a mux when en is 0. Style B removes the mux and stops the clock instead, through an ICG driven by en and clk.

    Compare the two clock pins first, then the D inputs.

    • Style A: the flop is clocked on every edge. When en is 0 the mux feeds q back to D, so the flop reloads its own value and its clock pin still toggles.

    • Style B: the mux is gone. The ICG stops gclk when en is 0, so the flop is not clocked at all and holds its value for free.

    • Same behaviour, different power: both registers load d when en is 1 and hold when en is 0. Synthesis can turn style A into style B for you when the register group is large enough.

    Rules for explicit gating

    1. Use the library ICG cell, via a wrapper module, not a hand-written AND or latch. Keep the wrapper so that you can swap models for simulation, FPGA or ASIC.

    2. Drive the enable from registered logic (or a short, well-bounded path). A late enable fails the gating check.

    3. Always provide a test enable (te) so that scan shifting still clocks the gated flops.

    4. Put reset on the gated flops with an asynchronous reset (as above) or ensure the clock runs during reset; a synchronous reset on a gated clock will not take effect while the clock is off.

    5. Never drive data from the gated clock domain into the ungated one without remembering the skew between them. They are the same clock source, but the gate adds insertion delay on one branch: the clock-tree tool balances the two branches only as well as its target allows, and STA must see the remaining skew on every crossing path (it often shows up as a hold problem).

    A synchronous reset on gated flops needs the clock to arrive. If the enable is 0 at reset, the flops never see the reset edge and keep their old value. Either force the enable on during reset (en | ~rst_n) or use an asynchronous reset.

    To see whether a tool gated your registers, check the synthesis report for the number of clock gates inserted and the registers they cover. If the count is zero for a block you expected to be gated, look at the enable: the common cause is registers that do not share a common enable.

    Check yourself Why does the checker drive inputs 1 ns after a falling edge and compare 1 ns after a rising edge?

    Driving during the low phase avoids the latch-closing edge; delayed comparisons observe completed NBA updates. These offsets define a nonracy ideal-model stimulus, not measured clock-to-Q or library setup/hold margins.

    Testbench

    The draft checker uses independent load/hold references, directed load/hold and 300-cycle idle/wake-up scenarios, then 2,000 random functional cycles. Under test enable the gated register must load every edge even with en=0, while the plain enable register holds.

    icg.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    `timescale 1ns/1ps
    
    module icg (input logic clk, en, te, output logic gclk);
      logic en_l;
      always_latch if (!clk) en_l = en | te;
      assign gclk = clk & en_l;
    endmodule
    
    // Style A: a register with an enable (what you normally write; synthesis may turn it into a gated clock)
    module reg_en #(parameter int W = 8) (input logic clk, rst_n, en, input logic [W-1:0] d, output logic [W-1:0] q);
      always_ff @(posedge clk or negedge rst_n)
        if (!rst_n)  q <= '0;
        else if (en) q <= d;
    endmodule
    
    // Style B: the same register behind an explicit clock gate; no enable mux in front of the flops
    module reg_gated #(parameter int W = 8) (input logic clk, rst_n, en, te, input logic [W-1:0] d, output logic [W-1:0] q, output logic gclk);
      icg u_icg (.clk, .en, .te, .gclk);
      always_ff @(posedge gclk or negedge rst_n)
        if (!rst_n) q <= '0;
        else        q <= d;
    endmodule
    

    The checker drives en, te and d 1 ns after falling source edges and samples outputs 1 ns after rising edges. The independent reference loads on en for style A and en|te for style B; changing test data checks bypass semantics, not just edge counts. The 300 idle cycles must deliver zero gated edges, retain 0x3c, then load 0xa5 on the first enabled edge and hold it on the next idle edge.

    In the random part, 380 of the 2,000 cycles delivered a gated-clock edge.

    • Write a plain enable by default. Synthesis can replace the feedback mux with a clock gate where it pays off.

    • An explicit gate uses the library ICG through a wrapper, a registered enable and a test enable (te).

    • A synchronous reset on gated flops needs the clock to run. Force the enable on during reset or use an asynchronous reset.

    Rule of thumb: if the synthesis report shows zero clock gates for a block you expected to gate, look at the enable.

    How this was checked

    Testbench, run with Icarus Verilog 13.0 (2026-10-16): iverilog -g2012 -s tb_gated, then vvp with +SEED=163, prints PASS. In the random part, 380 of the 2,000 cycles delivered a gated-clock edge. The 300 idle cycles deliver zero gated edges and the register keeps 0x3c.

    The comparison is a finite model check. It is not formal equivalence or physical signoff, and it measures no activity or power reduction. The stimulus offsets define a non-racy ideal-model stimulus, not measured clock-to-Q or library setup and hold margins.

    • Practice: Clock gating design and verification

    • Code lab: Clock-gate control FSM

    • Interview: run a mock interview on this topic

    Related topics

    • Enable quality rules

    Previous

    138 / 350

    Next: Enable Quality Rules

    Up next

    Up nextEnable Quality Rules

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Why Clock Gating Saves Power
    • Latch-Based Gating: Timing and Signoff