Where the Clock Comes From
Find the clock a concurrent assertion uses, set it with default clocking or a clocking block, and gate it safely with iff.
You Will Be Able To
- Find the clock of any concurrent assertion: explicit, from its procedure, or from default clocking.
- Write assertions with
default clockingand with a clocking block event@(cb). - Explain why
@(posedge clk iff en)is safer than a gated clock net, and how it differs fromdisable iff.
- Lesson
- A1.6
- Time
- 25 min
- Runs on
- Verilator
- Check
- 4 questions
A low-power block had its clock gated by en, and its assertions used the gated net, @(posedge gclk). One night a regression failed at 46 ns, between two clock edges. No flip-flop changed there. The enable had risen while the clock was high, so the net made an edge that no register saw.
Each column is one moment. The real clock rises at 45 and 55, with en low both times. The gated net rises at 46 anyway.
An Explicit Clock
The surest way to clock an assertion is to write the clock first: assert property (@(posedge clk) busy |=> !busy);. This leading clocking event can also sit at the start of a named property or sequence. Then every assertion that uses that name gets its clock.
An explicit clock always wins. No default or procedure can change it.
Default Clocking
default clocking dc @(posedge clk); endclocking gives a clock to every concurrent assertion in the module that has none of its own. It saves writing the clock in fifty rules, and changing one line moves them all.
The default covers its module, interface or checker. It does not reach into instances of other modules: each module needs its own. The cost is readability, since a property without a clock sends the reader looking for the default.
Clocking Blocks: @(cb)
A clocking block names an event and its signals: clocking cb @(posedge clk); input ok; endclocking. An assertion can use the block's event as its clock, @(cb). It can also read the block's signals as cb.ok.
With the default input skew, #1step, a clocking block samples just before the edge. That is the same value a concurrent assertion samples, so @(cb) cb.ok and @(cb) ok report at the same edges.
Gated Clocks: The Net or iff
A gated clock stops the clock while a block is idle. In RTL it is often a net such as gclk = clk & en. Clocking an assertion on that net is risky. If en changes while clk is high, the net makes an edge that is not a clock edge.
Real designs gate a clock with a latch-based cell that blocks this glitch. The plain AND here is a modelling shortcut, and it shows why that cell exists. Some books clock a property on such a net without this warning.
@(posedge clk iff en) says the same thing safely. The assertion uses only real edges of clk, and an edge counts only if en is 1 at that edge. In the example, the false edge at 46 fails on_net, while on_iff stays quiet.
Each column is one moment (measured on Verilator 5.052). The clock rises at 15, 25 and 35. Both forms check at 15 and 35 and skip 25. Only the gated net also checks at 28, where en pulses while clk is high.
iff and disable iff Do Different Things
They look alike and do different things. iff en in the clock removes edges: an attempt in progress simply waits for the next edge with en high. disable iff (!en) keeps every edge, but cancels every attempt in progress when en goes low.
The rule is req |=> ack on posedge clk, written both ways (measured on Verilator 5.052). With iff, the edge at 25 is skipped and the attempt fails at 35. With disable iff, the attempt is cancelled when en falls, and nothing fails.
Which Clock Wins
- Control / FSM
- Clock / reset
- Result
- Control
- Explicit
@(negedge clk) okuses the falling edge, even with a rising-edge default in the module. - From the procedure
An
assert property (ok)insidealways @(posedge clk)takes that edge. So does one inalways @(posedge clk or posedge rst), when the body readsrst. The next section has the full rule. - Default
A bare
assert property (ok)at module level takes the default clocking. - Nothing
With no clock anywhere, a concurrent assertion is illegal: the compiler rejects it.
Read the diagram as text
- Its own clock?: @(...) in the assertion, property or sequence
- One clock edge in its procedure?: one edge whose signal the body does not read
- A default clocking?: in this module, interface or checker
- That clock: explicit always wins
- The procedure's edge: inferred from its event control
- The default clock: e.g. @(posedge clk)
- Compile error: no clock for the assertion
- Its own clock? → That clock: yes
- Its own clock? → One clock edge in its procedure?: no
- One clock edge in its procedure? → The procedure's edge: yes
- One clock edge in its procedure? → A default clocking?: no
- A default clocking? → The default clock: yes
- A default clocking? → Compile error: no
Clock resolution for one clock (IEEE 1800-2023 16.14.6 and 16.16). Checkers can also take their clock from the place they are instanced.
The Clock a Procedure Gives
A concurrent assertion inside a procedure can take its clock from the procedure. The standard infers that clock only in one case (IEEE 1800-2023 16.14.6). The procedure has one event control and no other delay. And exactly one of its edge events names a signal that the body does not read.
That is why the usual flip-flop with an asynchronous reset works. Its event control has two edges, posedge clk and posedge rst. The body reads rst, so only posedge clk is left, and that is the clock.
| Procedure | Standard | Verilator 5.052 (measured) |
|---|---|---|
always @(posedge clk), body does not read clk | clock is posedge clk | checks at posedge clk |
always @(posedge clk or posedge rst), body reads rst | clock is posedge clk | same, if the assertion sits in the clocked branch |
always @(posedge clk or posedge rst), body reads neither | no clock: two edges are left | compiles; checks at both edges |
always @(clk) | no clock: no edge keyword | compiles; checks at every change of clk |
always @(posedge clk), body reads clk | no clock: the body reads the signal | compiles; checks at posedge clk |
a #1 delay inside the procedure | no clock: a second timing control | compiles; checks 1 ns after the edge |
When the standard infers no clock, the default clocking applies. With no default either, the assertion is illegal.
Cycle Delays in Procedural Code
Default clocking also gives procedural code a cycle delay. ##2; in an initial block waits for two edges of the default clock. Without a default clocking, ##2; in procedural code does not compile.
In the example, the bench reaches ##2; at 49 ns. The next two rising edges are 55 and 65, so it prints at 65.
Try It
The gated net rises at 46, when en rises while clk is high. on_net samples busy and done there and fails. No register in the block was clocked at 46. on_iff uses only the real edges at 45 and 55, and en is low at both, so it checks nothing.
on_dflt has no clock of its own, so it takes the default: busy is 1 at 45 and 0 at 55, so it passes. Change the gate to @(posedge clk iff !en) and predict which edges on_iff checks.
t=46 on_net failed t=65 done waitingCheck Yourself
Common Mistakes
Wrong Clock assertions on the gated net gclk = clk & en.
If en changes while clk is high, the net makes an edge that no register sees, and the assertion checks there.
Fix Clock on the real clock and qualify it: @(posedge clk iff en).
assign gclk = clk & en;
assert property (@(posedge gclk) p);assert property (@(posedge clk iff en) p);Wrong Use disable iff (!en) to pause a rule while the clock is gated.
disable iff cancels attempts in progress, so a request made before gating is never checked.
Fix Use iff en in the clock to skip gated edges and keep attempts waiting.
Wrong Assume a default clocking in the testbench top also clocks assertions inside the DUT.
A default clocking does not descend into module instances.
Fix Give each module with assertions its own default clocking, or write explicit clocks.
Remember
- An explicit clock in the assertion, property or sequence always wins.
- Without one, a procedure gives its one clock edge: the edge whose signal the body does not read. Otherwise the default clocking applies.
- A default clocking covers its own module and does not reach into instances.
@(posedge clk iff en)uses real clock edges only; a gated clock net can make false edges.iffskips edges and keeps attempts waiting;disable iffcancels them.