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 clocking and with a clocking block event @(cb).
  • Explain why @(posedge clk iff en) is safer than a gated clock net, and how it differs from disable 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.

A gated net with an extra edge
012345time (ns)404546475055clkengclk = clk & engclk rises: a false clock edge
Scroll horizontally ↔

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.

The gated net and iff, edge by edge
012345time (ns)152025283235clkrisesfallsriseshighlowrisesen1falls0pulsesrises1gclk = clk & enrisesfallslowriseslowrises@(posedge gclk) checksyesnoyesnoyes@(posedge clk iff en) checksyesnoyesa false edge: only the net checks here
Scroll horizontally ↔

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.

One request, gated for one edge
012clock edge (ns)152535reqenackwith iff enstartswaitsfailswith disable iff (!en)startscancelledidleen fell at 20only iff still checks ack
Scroll horizontally ↔

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

Which Clock Does This Assertion Use?Ask the questions in order. The first yes gives the clock.
  • Control / FSM
  • Clock / reset
  • Result
  • Control
Which clock does this assertion use?Ask the questions in order. The first yes gives the clock. control Its own clock? @(...) in theassertion, propertyor sequence control One clock edge inits procedure? one edge whose signalthe body does notread control A defaultclocking? in this module,interface or checker clock reset That clock explicit always wins clock reset The procedure'sedge inferred from itsevent control clock reset The default clock e.g. @(posedge clk) result Compile error no clock for theassertion yesnoyesnoyesno
  1. control Its own clock?@(...) in the assertion, property or sequence
    • yes → That clock
    • no → One clock edge in its procedure?
  2. clock reset That clockexplicit always wins
  3. control One clock edge in its procedure?one edge whose signal the body does not read
    • yes → The procedure's edge
    • no → A default clocking?
  4. clock reset The procedure's edgeinferred from its event control
  5. control A default clocking?in this module, interface or checker
    • yes → The default clock
    • no → Compile error
  6. clock reset The default clocke.g. @(posedge clk)
  7. result Compile errorno clock for the assertion
  1. Explicit

    @(negedge clk) ok uses the falling edge, even with a rising-edge default in the module.

  2. From the procedure

    An assert property (ok) inside always @(posedge clk) takes that edge. So does one in always @(posedge clk or posedge rst), when the body reads rst. The next section has the full rule.

  3. Default

    A bare assert property (ok) at module level takes the default clocking.

  4. 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.

ProcedureStandardVerilator 5.052 (measured)
always @(posedge clk), body does not read clkclock is posedge clkchecks at posedge clk
always @(posedge clk or posedge rst), body reads rstclock is posedge clksame, if the assertion sits in the clocked branch
always @(posedge clk or posedge rst), body reads neitherno clock: two edges are leftcompiles; checks at both edges
always @(clk)no clock: no edge keywordcompiles; checks at every change of clk
always @(posedge clk), body reads clkno clock: the body reads the signalcompiles; checks at posedge clk
a #1 delay inside the procedureno clock: a second timing controlcompiles; 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.

RUNVerilator · simulator service
Edit the code, then run it
Expected: t=46 on_net failed t=65 done waiting

Check Yourself

Predict the outputThe module's default clock is the falling edge. Predict the exact output.
module tb;
  logic clk = 0;
  always #5 clk = ~clk;                  // rising at 5, 15, 25; falling at 10, 20, 30
  logic ok = 1;
  default clocking dc @(negedge clk); endclocking
  a: assert property (ok) else $display("default: fail at %0t", $time);
  b: assert property (@(posedge clk) ok) else $display("explicit: fail at %0t", $time);
  initial begin
    #12 ok = 0;                          // low from 12 to 18
    #6  ok = 1;
    #20 $finish;
  end
endmodule
ConceptA module has default clocking @(posedge clk). An assertion with no clock of its own sits in a module instanced inside it. Which clock does it use?
ConceptGated-off edges must not be checked. But a request made before gating must still get its answer afterwards. Which form fits?
Read the waveformgclk = clk & en. At which moments does @(posedge gclk) see an edge?
clk, en and the gated net
012345time (ns)51215222528clken
Scroll horizontally ↔

Each column is one moment. clk rises at 5, 15 and 25.

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).

Before
assign gclk = clk & en;
assert property (@(posedge gclk) p);
After
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.
  • iff skips edges and keeps attempts waiting; disable iff cancels them.

Practice

Report a problem with this page