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.
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
- I/O
- Storage
- Scoreboard
- Data
- Register A is the reference
It is the RTL you wrote: a flop that loads
dwhenenis 1. Nobody doubts what it does. - 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.
- The check
The tool tries every sequence of
enandd. 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.
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 clockEach 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 B | Task | Result |
|---|---|---|
| Clock gate with its latch | prove | PASS: proved for every step |
| Clock gate with its latch | bmc, depth 20 | PASS for the first 19 steps |
| Bare AND gate | bmc, depth 20 | FAIL at reported step 3 |
| Bare AND gate, enable promised stable while the clock is high | prove | PASS: 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.
phase is the level of the design clock. The solver chose en and d.- Cycle 0
The clock is low.
enis 0, so neither register is about to load. The solver puts 8 ond. - Cycle 1
The clock is high, and
enrises in this half. The AND gate passes it at once:gclkgoes to 1. That is a rising edge for register B. - Cycle 2
Register B has loaded 8. Register A saw
enat 0 before the clock edge, so it kept 0. The outputs differ. - 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
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.
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.
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
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.