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_gclk and $changed_gclk on a trace.
  • Choose between $rose and $rose_gclk in 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.

What the fast clock sees between two edges of clk
012345fast tick (ns)455565758595clkselsel changed since the last tickclk rose since the last ticksel changed, clk did not riseand again
Scroll horizontally ↔

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.

A global clocking, and two ways to use it
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.

Which Global Clocking Applies?The standard looks in the module that holds the reference, then in its parent instance, and so on up to the top. The first declaration found wins.
  • Environment
  • DUT
  • Property
  • Structure
call: who calls whom
Which global clocking applies?The standard looks in the module that holds the reference, then in its parent instance, and so on up to the top. The first declaration found wins. env tb global clocking@(posedge sys) dut u_fast its own: @(posedgefck) dut u_slow no declaration property rule in u_fast @($global_clock) property rule in u_slow @($global_clock) found herenot hereask the parent
  1. property rule in u_fast@($global_clock)
    • found here → u_fast
  2. dut u_fastits own: @(posedge fck)
  3. property rule in u_slow@($global_clock)
    • not here → u_slow
  4. dut u_slowno declaration
    • ask the parent → tb
  5. env tbglobal clocking @(posedge sys)
  1. A rule in u_fast

    The module u_fast declares its own global clocking. The lookup stops there: the rule ticks on fck.

  2. A rule in u_slow

    The module u_slow declares none. The lookup moves to the parent instance.

  3. The parent answers

    The parent tb declares one, so the rule in u_slow ticks on sys. 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_clock needs 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.

A counter d on the global clock, read at the clk edge at 50
012345global tick (ns)515253545clk edge 50d sampled123456$past_gclk(d): one global tick backthe clk edge at 50
Scroll horizontally ↔

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

CodeStandardVerilator 5.052 (measured)
$global_clock in a module with no declaration; the parent has onethe parent's global clocking appliescompile 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 blockillegalaccepted (an unnamed one stops on an internal error)
two global clocking declarations in one moduleillegalcompile error
$global_clock with no declaration anywhereillegalcompile 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.

RUNVerilator · simulator service
Edit the code, then run it
Expected: 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=1

Check Yourself

Predict the outputv is declared with the value 9 and never written. Predict what the first global tick prints.
module tb;
  logic sys = 0;
  always #5 sys = ~sys;
  global clocking @(posedge sys); endclocking
  logic [3:0] v = 4'd9;
  initial begin
    @($global_clock);
    $display("past=%0d changed=%b rose=%b", $past_gclk(v), $changed_gclk(v), $rose_gclk(v));
    $finish;
  end
endmodule
Spot the bugThe rule is "sel changes only in the global tick that sees clk rise". The bench makes two legal updates and one glitch. Which option misses the glitch?
ConceptA module uses $global_clock and declares no global clocking. Its parent instance declares one. What does the standard say?
ConceptA 4-bit count goes from 5 to 6 between two global ticks. Which functions are true at the second tick?
ConceptAn assertion is clocked by a slow clk. What does $stable_gclk(d) compare at an edge of clk?

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.

Before
assert property (@(posedge clk)
  $rose(x) |-> ok);
After
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); endclocking names the primary clock; $global_clock refers 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_gclk and $fell_gclk read bit 0; $stable_gclk and $changed_gclk read 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

Report a problem with this page