Global Clocking and Past Functions
Declare a global clock and read the value one global tick back with $past_gclk, $rose_gclk, $fell_gclk, $stable_gclk and $changed_gclk.
You Will Be Able To
- Declare a global clocking and refer to it with
$global_clock. - Say which global clocking a module uses.
- Predict
$past_gclk,$rose_gclk,$fell_gclk,$stable_gclkand$changed_gclkon a trace. - Choose between
$roseand$rose_gclkin an assertion on a slow clock.
- Lesson
- A6.3
- Time
- 25 min
- Runs on
- Verilator
- Check
- 5 questions
A mux select sel is a register on the design clock clk. It glitched in the middle of a cycle and came back before the next edge. Every assertion on clk passed, because clk never sampled the glitch. A faster clock did.
Values sampled at each rising edge of the fast clock. clk rises at 50 and 90, and reads sel as 0 and then 1. The two changes in between need a faster observer.
Global Clocking and $global_clock
A global clocking names one event as the primary clock of a design, or of a part of it. It is usually the fastest clock. Formal tools treat it as the smallest step of time.
global clocking gck @(posedge sys); endclocking // the name gck is optional
always @(gck) ticks++; // by name
always @($global_clock) ticks++; // by the system function
tick_rule: assert property (@($global_clock) !(wr && rd));$global_clock stands for the event of the global clocking that applies at that place. In an assertion it behaves like any other clock. The declaration may sit in a module, an interface, a checker or a program, and each may hold only one.
- Environment
- DUT
- Property
- Structure
- A rule in u_fast
The module
u_fastdeclares its own global clocking. The lookup stops there: the rule ticks onfck. - A rule in u_slow
The module
u_slowdeclares none. The lookup moves to the parent instance. - The parent answers
The parent
tbdeclares one, so the rule inu_slowticks onsys. If the top had none either, the reference would be an error.More context
Verilator 5.052 does not look in the parent. On it, every module that uses
$global_clockneeds its own declaration.
Read the diagram as text
- tb: global clocking @(posedge sys)
- u_fast: its own: @(posedge fck)
- u_slow: no declaration
- rule in u_fast: @($global_clock)
- rule in u_slow: @($global_clock)
- rule in u_fast → u_fast: found here
- rule in u_slow → u_slow: not here
- u_slow → tb: ask the parent
Standard behaviour (IEEE 1800-2023 14.14). The nearest declaration up the hierarchy applies.
$past_gclk: One Global Tick Back
$past_gclk(v) is the sampled value of v at the last global tick before now. It takes no depth and no gate: it always looks one global tick back.
The difference from $past shows on a slower clock. In an assertion on clk, $past(v) goes back one tick of clk. $past_gclk(v) still goes back one tick of the global clock.
At the clk edge at 50, $past_gclk(d) is 5, the sample of the tick at 45. $past(d) is 2, the sample of the clk edge at 10.
$rose_gclk: Bit 0 Went to 1 Since the Last Global Tick
$rose_gclk(v) is true when bit 0 of v is 1 now and was not 1 at the last global tick. It is $rose with the global clock as its reference.
On the assertion clock
assert property (@(posedge clk)
$rose(x) |-> ok);
Compares with the last edge of clk. A rise 30 ns ago still counts.
On the global clock
assert property (@(posedge clk)
$rose_gclk(x) |-> ok);
Compares with the last global tick. Only a rise in the last fast step counts.
$fell_gclk: Bit 0 Went to 0
$fell_gclk(v) is true when bit 0 of v is 0 now and was not 0 at the last global tick. Like $fell, it reads only bit 0 of a vector.
So a vector that counts up can "fall". Going from 3 to 4 takes bit 0 from 1 to 0. Use these two functions on one-bit signals, or compare vectors with $past_gclk.
$stable_gclk: The Whole Value Is the Same
$stable_gclk(v) is true when the whole value of v equals its value at the last global tick. Every bit counts, not only bit 0.
A typical rule: while hold is high, data must not move between global ticks.
$changed_gclk: The Value Differs
$changed_gclk(v) is the opposite of $stable_gclk(v). It is true when the value differs from the one at the last global tick.
It makes a good trigger: "when sel changes, the design clock must just have risen". That is the rule that catches the glitch of the opening story.
Where the Tool and the Standard Part
The five past functions are defined through the clocked forms of the ordinary ones. $past_gclk(v) is $past(v, , , @($global_clock)), and $rose_gclk(v) is $rose(v, @($global_clock)).
| Code | Standard | Verilator 5.052 (measured) |
|---|---|---|
$global_clock in a module with no declaration; the parent has one | the parent's global clocking applies | compile error: no definition found |
$past(v, , , @($global_clock)) | the same as $past_gclk(v) | compile error: clock argument unsupported |
a named global clocking inside a generate block | illegal | accepted (an unnamed one stops on an internal error) |
two global clocking declarations in one module | illegal | compile error |
$global_clock with no declaration anywhere | illegal | compile error |
IEEE 1800-2023 14.14 and 16.9.4. The tool column was measured on 2026-11-12.
On this site, declare the global clocking in each module that uses it, outside any generate block. That code is legal in the standard and runs on Verilator 5.052.
Try It
The design clock samples sel as 0, 0, 1, 1. That is a clean single change. The global clock samples it every 10 ns. It sees it fall at 65 and rise at 75, with no rise of clk in either tick.
The legal updates pass. The update at 50 is first sampled at 55, and that tick also sees clk rise. Change #12 sel = 0; to #22 sel = 0; and predict the two failure times.
t=10 clk edge: sel=0 t=50 clk edge: sel=0 t=65 sel changed with no clock edge t=75 sel changed with no clock edge t=90 clk edge: sel=1 t=130 clk edge: sel=1Check Yourself
Common Mistakes
Wrong Use $rose(x) in an assertion on a slow clock to ask "did x rise just now?".
$rose compares with the last tick of the slow clock, so a rise many fast ticks ago still counts.
Fix Use $rose_gclk(x), which compares with the last global tick.
assert property (@(posedge clk)
$rose(x) |-> ok);assert property (@(posedge clk)
$rose_gclk(x) |-> ok);Wrong Read $rose_gclk(count) and $fell_gclk(count) as "the count went up" and "the count went down".
Both read only bit 0, so a count that goes from 3 to 4 reports a fall.
Fix Compare vectors directly: count > $past_gclk(count).
Wrong Expect the global clock to catch every glitch.
It samples once per tick, so a pulse that starts and ends between two ticks is never seen.
Fix Pick a global clock at least as fast as the shortest event you must see.
Remember
global clocking @(event); endclockingnames the primary clock;$global_clockrefers to it.- The nearest declaration up the hierarchy applies; on Verilator 5.052, declare it in each module that uses it.
- The five past functions compare the sample now with the sample at the last global tick.
$rose_gclkand$fell_gclkread bit 0;$stable_gclkand$changed_gclkread the whole value.- On a slow assertion clock,
$past(v)goes back one slow tick and$past_gclk(v)one global tick.
Practice
Quick reference: $rose, $fell, $stable and $past