Draft preview. Lessons are being written and reviewed.

Digital Design / Module 4: Sequential logic

24. Enables and clock gating

Hold a value and save power.

Lecture coming soon

See it move

Enables

A flop that should sometimes hold its value needs an enable.

always_ff @(posedge clk)
  if (en) q <= d;

In hardware, this is a mux in front of D, feeding Q back when en is low. It works well, but the flop still receives its clock, so its clock pin keeps burning power, plus a mux per bit.

Clock gating

Rather than holding the value with a mux, stop the clock from reaching a group of flops. They keep their values, since no edge arrives. For a 32-bit register, one gate replaces 32 muxes and removes the clock-pin activity.

Why a plain AND doesn't work

assign gclk = clk & en; looks right. But if en changes while clk is high, the output changes partway through a pulse, creating a runt pulse or a false edge. The animation above shows exactly this. Flops treat these glitches as real clock edges.

The integrated clock gate

An ICG cell adds a that is transparent while the clock is low:

// A model of the behaviour; real designs use the library's ICG cell
always_latch
  if (!clk) en_lat = en;

assign gclk = clk & en_lat;

The latch can change only during the low phase, and the AND output is then held low anyway. Once the clock rises, en_lat is frozen, so every pulse is whole.

Common mistake

Writing your own gate out of a latch and an AND in production RTL. Use the library's ICG, which is characterised and understood by clock-tree tools, or let synthesis insert gating automatically. Remember that a gated domain also needs its enable to meet timing against the clock edge.

Key ideas

  • An enable is a mux feeding back Q.
  • Gating stops the clock so the flops don't toggle.
  • Use an integrated clock gate; a raw AND can glitch.

Your exercise

Convert an enable register to a clock-gated version in concept.

Find the bug

This code has one deliberate bug. Read the symptom, then click the line you think is wrong.

What goes wrong: When en goes low, q should hold its value. Instead q drops to 0.

Interview questions

coreWhy not gate a clock with plain AND?

basicWhat hardware does if (en) q <= d; inside a clocked block describe?

basicWhy does clock gating save power compared with an enable mux?

coreSomeone gates a clock with a plain AND gate. The enable comes from logic that can change while the clock is high. What goes wrong?

assign gclk = clk & en;

coreExplain how this clock gate model avoids glitches, and why its latch is open while the clock is low rather than high.

always @(*)
  if (!clk) en_lat = en;

assign gclk = clk & en_lat;

coreA 32-bit register is loaded on one cycle in every ten. Over 100 clock cycles, how many rising clock edges reach its flops with an enable mux, and with clock gating?

coreIs it always worth gating the clock of a register that has an enable?

advancedIn a clock-gated domain, by when must the enable be stable, and why is that timing path often tighter than a normal flop-to-flop path?

advancedThis hand-written clock gate still produces false edges in simulation. What is the bug?

always @(*)
  if (clk) en_lat = en;

assign gclk = clk & en_lat;

Practise these 9 questions with animations