FVO — Formal Verification Online
Lesson 13.2 · Auxiliary Code and Modelling

Counters, sticky flags and shadow registers

1. Counters: "how many are in flight?"

A block issues requests and later receives responses. The spec says at most MAX_OUT may be outstanding. Count them in the testbench and the property is one line:

outstanding counter
// outstanding = requests sent - responses received
logic [3:0] outstanding;
always_ff @(posedge clk)
  if (rst) outstanding <= '0;
  else     outstanding <= outstanding + 4'(req_fire) - 4'(rsp_fire);

a_max_out:   assert property (outstanding <= MAX_OUT);
a_no_orphan: assert property (rsp_fire |-> outstanding != 0);       // no response without a request
a_stop_req:  assert property (outstanding == MAX_OUT |-> !req_fire); // design must stop issuing
c_full_load: cover  property (outstanding == MAX_OUT);              // the model is exercised
01234567clkreq_firersp_fireoutstanding0121010
The counter is the auxiliary model. Here the column shows the counter value seen at each tick, before that tick's fires are added.

2. Sticky flags: "has it ever happened?"

A flag that is set by an event and never cleared (until reset) answers "since reset, has X happened?".

sticky flag
// configuration must be written before the first transfer is started
logic cfg_done;
always_ff @(posedge clk)
  if (rst)            cfg_done <= 1'b0;
  else if (cfg_write) cfg_done <= 1'b1;

a_cfg_first: assert property (start |-> cfg_done || cfg_write);

Variants clear the flag on a second event, which gives "X happened since the last Y" — for example "an error was reported since the last status read".

3. Shadow registers: "what was the last value?"

When an output must reflect a value written earlier, keep a copy:

shadow register
// a status register must read back exactly what software last wrote
logic [7:0] shadow;
always_ff @(posedge clk)
  if (rst)                         shadow <= 8'h00;          // documented reset value
  else if (wr_en && addr == CTRL)  shadow <= wdata;

a_readback: assert property (rd_en && addr == CTRL |-> rdata == shadow);

This is exactly how CSR apps (Chapter 7) work under the hood: one shadow per register field, generated from the register description.

Discussion

No comments yet.

Was this page helpful?

Tip: select any text on the page before clicking Report and it will be quoted in your report.