Proving a Clock Gate Changed Nothing

Check that a gated register behaves like the ungated one for every enable timing, and read the trace when it does not.

You Will Be Able To

  • Set up two versions of a register so that a tool can compare them.
  • Read a counterexample and name the enable timing that breaks a bare AND gate.
  • Explain what a bounded pass and a full proof each establish.
Lesson
W2.3
Time
25 min
Runs on
SymbiYosys
Check
5 questions

A team gated one register by hand with an AND gate, and every directed test passed. In the lab the register sometimes loaded a new value while its enable was low.

The counterexample for a bare AND gate
0123clkphasefreeenfreed80gclkq_muxq_gate08en rises while the clock is highq_gate loaded 8
Scroll horizontally ↔

Measured: bare AND gate, mode bmc, depth 20, smtbmc yices: FAIL at reported step 3.

A formal tool finds this in seconds: the register behind the AND gate loads 8, and the enable-mux register keeps 0.

Two Registers That Must Always Agree

The Same Inputs Drive Both VersionsArrows show signals. The clock, the enable and the data go to both registers. A check compares the two outputs in every step.
  • I/O
  • Storage
  • Scoreboard
  • Data
The same inputs drive both versionsArrows show signals. The clock, the enable and the data go to both registers. A check compares the two outputs in every step. io Inputs en and d, free inevery step storage Register A Enable mux, plainclock storage Register B Clock gate, no mux scoreboard Check q_mux equals q_gate en, den, dq_muxq_gate
  1. io Inputsen and d, free in every step
    • en, d → Register A
    • en, d → Register B
  2. storage Register AEnable mux, plain clock
    • q_mux → Check
  3. storage Register BClock gate, no mux
    • q_gate → Check
  4. scoreboard Checkq_mux equals q_gate
  1. Register A is the reference

    It is the RTL you wrote: a flop that loads d when en is 1. Nobody doubts what it does.

  2. Register B is the gated version

    It is what the netlist holds after clock gating: a flop with no mux, on a clock that the gate can stop.

  3. The check

    The tool tries every sequence of en and d. If the two outputs can ever differ, it prints the sequence.

Read the diagram as text
  • Inputs: en and d, free in every step
  • Register A: Enable mux, plain clock
  • Register B: Clock gate, no mux
  • Check: q_mux equals q_gate
  • Inputs → Register A: en, d
  • Inputs → Register B: en, d
  • Register A → Check: q_mux
  • Register B → Check: q_gate

This is an equivalence check: two designs, the same inputs, and a proof that the outputs match.

Lesson W2.1 replaced enable muxes with a clock gate to save power. That change must not alter what the register stores. A simulation can show it for the cases you thought of. A formal tool checks all of them.

The setup needs no testbench. Both versions sit in one module and share their inputs. One assertion says that their outputs are equal.

A Model with Two Steps per Clock Period

A clock gate is about what happens inside a clock period. Its latch is open while the clock is low and closed while it is high. So the model needs to see both halves.

Part of the lab. clk is the fast clock of the model; phase is the clock of the design.
reg phase = 0;                       // the level of the design clock
always @(posedge clk) phase <= !phase;

reg en_hold = 0;                     // the latch inside the clock gate
wire en_lat = phase ? en_hold : en;  // open while the clock is low
always @(posedge clk) en_hold <= en_lat;
wire gclk = phase && en_lat;         // the gated clock

Each step of the model is half a clock period. A register named phase toggles in every step, and it stands for the level of the design clock. The enable en is free in every step, so it can change in the low half or the high half.

A flop loads when its clock rises. In the model that is a step where the clock is 1 and was 0 one step before.

The Proof, and What Breaks It

Version of register BTaskResult
Clock gate with its latchprovePASS: proved for every step
Clock gate with its latchbmc, depth 20PASS for the first 19 steps
Bare AND gatebmc, depth 20FAIL at reported step 3
Bare AND gate, enable promised stable while the clock is highprovePASS: proved for every step

Measured with SymbiYosys and the yices solver on this site.

With the real clock gate the tool proves the assertion. The latch passes the enable only while the clock is low. So the gated clock rises exactly when the mux would load.

Now read the failing trace of the AND gate again, one step at a time.

Walking the CounterexampleOne column is half a clock period. phase is the level of the design clock. The solver chose en and d.
0123clkphasefreeenfreed80gclkq_muxq_gate08en rises while the clock is highq_gate loaded 8
Scroll horizontally ↔
  1. Cycle 0

    The clock is low. en is 0, so neither register is about to load. The solver puts 8 on d.

  2. Cycle 1

    The clock is high, and en rises in this half. The AND gate passes it at once: gclk goes to 1. That is a rising edge for register B.

  3. Cycle 2

    Register B has loaded 8. Register A saw en at 0 before the clock edge, so it kept 0. The outputs differ.

  4. Cycle 3

    The tool reports the failure one step after the state it sampled.

Measured: bare AND gate, mode bmc, depth 20, smtbmc yices: FAIL at reported step 3.

The AND gate created a clock edge in the middle of the high half. The enable mux never loads there.

The last row is a warning. Promise the tool that the enable never changes while the clock is high, and the bare AND gate passes. In a real design that promise is false: the enable comes from a flop, and it changes just after the rising edge. The latch is what makes the promise true.

A Bounded Pass and a Proof Are Different Claims

The table has two passing rows for the real clock gate. They do not say the same thing.

The task bmc at depth 20 checks the first 19 steps after reset. Here that is nine and a half clock periods. It says nothing about step 100.

The task prove adds an induction step. It shows that the two registers agree after any number of steps. This small model needs both: the bounded run finds bugs fast, and the proof closes the question.

A simulation is weaker than both. It shows the failure only if the test moves the enable during the high half, as lesson R2.3 did on purpose. The formal tool tries every timing without being told.

Asked in interviews
  1. How do you verify that clock gating did not change the design?

    Compare the design with gating on and off. Sequential equivalence checking gives both versions the same inputs and proves that the outputs always match. Simulation alone can miss the enable timings that matter.

  2. Why is a latch needed in a clock gate?

    The latch passes the enable only while the clock is low and holds it while the clock is high. So the gated clock can rise only when the clock itself rises. Without it the tool here finds a failure at step 3.

  3. What does a bounded model check not tell you?

    It checks a fixed number of steps from reset. A pass means no failure exists within that depth. Only an unbounded proof, for example by induction, covers every later step.

Try It

Run the task. The model holds register A, register B behind the clock gate, and one assertion. The result is a proof.

Now break the gate. Replace the three lines of the latch with wire gclk = phase && en; and run again. Read the trace from the failing step backwards.

Then put the latch back and change phase ? en_hold : en to !phase ? en_hold : en. The latch is now open in the wrong half. Predict the verdict before you run.

design.sv

props.sv

Use assert property (@(posedge clk) ...);. Leave blank for immediate assertions in the design.

Inputs are free unless constrained. Run to find a counterexample or check a proof.

Model: one positive-edge clock, binary data. Sampled history requires declaration-initialized variables; primary-input history is unsupported.

SBY summary and log

Check Yourself

Predict the outputThis version has the latch of the clock gate open while the clock is HIGH. The task is bmc at depth 20. Type the verdict (PASS or FAIL).
// Each step is half a clock period. phase is the level of the design clock.
module top(input clk, input en, input [3:0] d);
  reg phase = 0;
  always @(posedge clk) phase <= !phase;

  // what the design saw one step ago
  reg phase_q = 0, en_q = 0;
  reg [3:0] d_q = 0;
  always @(posedge clk) begin phase_q <= phase; en_q <= en; d_q <= d; end
  wire rise = phase && !phase_q;   // the design clock rose at the start of this step

  // Register A: an enable mux in front of a flop. It loads d when en was 1 before the edge.
  reg [3:0] q_mux = 0;
  always @(posedge clk) if (rise && en_q) q_mux <= d_q;

  // Register B: the same flop on a gated clock.
  reg en_hold = 0;                 // the latch inside the clock gate
  wire en_lat = !phase ? en_hold : en;   // open while the clock is HIGH
  always @(posedge clk) en_hold <= en_lat;
  wire gclk = phase && en_lat;
  reg gclk_q = 0;
  always @(posedge clk) gclk_q <= gclk;
  wire grise = gclk && !gclk_q;    // the gated clock rose at the start of this step
  reg [3:0] q_gate = 0;
  always @(posedge clk) if (grise) q_gate <= d_q;

  // the two registers must always agree
  always @(posedge clk) assert (q_mux == q_gate);
endmodule
Read the waveformIn this counterexample, in which step does the enable change in a way that the enable mux ignores?
The counterexample for a bare AND gate
0123clkphasefreeenfreed80gclkq_muxq_gate08
Scroll horizontally ↔

Measured: bare AND gate, mode bmc, depth 20, smtbmc yices: FAIL at reported step 3.

ConceptThe real clock gate passes bmc at depth 20. What has been shown?
ConceptWhich enable timing makes a bare AND gate differ from an enable mux?
ConceptA testbench changes en only on the falling clock edge, and runs a million random cycles. Both versions agree. Why is that weak evidence?

Common Mistakes

Wrong Trust a few directed tests of the gated design.

A test finds the bug only if it happens to move the enable while the clock is high.

Fix Compare the gated and ungated versions for every input sequence with a formal tool.

Wrong Compare the two versions only at reset.

The two registers agree at reset and first differ 2 steps later.

Fix Assert that the outputs agree in every step.

Wrong Use one model step per clock period, or assume the enable holds while the clock is high.

Then the enable never moves in the high half, and even a bare AND gate passes.

Fix Two steps per period, with the enable free in both halves.

Remember

  • Put the gated and the ungated register side by side, give them the same inputs, and assert that their outputs agree.
  • Let the enable change in either half of the clock period. That is where a bad gate fails.
  • A bare AND gate fails within 3 steps. The latch-based gate is proved for every step.
  • A bounded pass covers its depth only. A proof covers every step.
  • An assumption removes cases. Check that the real design keeps the promise.

Practice

Report a problem with this page