SystemVerilog Assertions introduced assert, assume, cover, and restrict at a glance. This article goes deeper into the three that matter for a typical simulation-plus-coverage-plus-formal flow — restrict is deliberately left out, since it's formal-only and simulators ignore it entirely.
11 min read | Intermediate Level
What You'll Learn
- Why the same property can be checked with
assertin simulation but treated as a constraint by a formal tool underassume - What
cover propertyactually tracks, and why "never failed" and "actually got exercised" are two different things - The exact syntax and semantics of
assert,assume, andcoveras separate statement types - How to declare a property once and reuse it across all three statement types, keeping the underlying check perfectly consistent
assert property: Checking a Property Holds
This is the statement type used throughout every other article in this chapter — it verifies that a property is true, and reports a failure when it isn't:
assert property (@(posedge clk) req |=> gnt);
cover property: Tracking How Often a Property Is Exercised
cover property takes the exact same kind of property, but instead of flagging failures, it tracks how many times the property actually succeeded during the run — contributing to a functional coverage report entirely independent of any pass/fail result from an assert:
property p_burst;
@(posedge clk) $rose(burst_req) ##[1:8] burst_ack;
endproperty
cover property (p_burst);
This tracks how many times a burst request was actually followed by an acknowledge within the expected window. If this count stays at zero across an entire regression, that's a real coverage gap — the scenario this property describes was never even exercised, regardless of whether any assertion ever failed.
This is exactly the situation covered in SystemVerilog Property Implication: an antecedent that never fires produces only vacuous successes from assert, which look identical to genuine, meaningful passes. cover property is the concrete tool that actually distinguishes the two — a property can pass every single time an assert checks it, purely because it was never given the chance to fail.
Quick Check
Q: If a test runs for a long time and assert property(p_burst) never reports a single failure, does that guarantee p_burst's scenario was actually tested?
Show Answer
No. It only guarantees the property was never violated — possibly because burst_req simply never rose during the entire test, in which case every check was vacuously true. cover property(p_burst) is what would reveal whether the scenario actually occurred at all.
assume property: A Constraint for Formal, a Check for Simulation
assume property has a genuinely dual nature depending on how it's used:
assume property (@(posedge clk) disable iff (!rst_n) req_valid !== 1'bx);
To a formal tool, this isn't something to verify — it's told to treat the property as a given fact, and to only explore input combinations consistent with it, constraining the state space it searches through. To a simulator, assume is typically checked in much the same way assert is, and a violation is still reported.
This matters because if a simulation testbench actually violates something declared as an assume, that's a real problem worth knowing about: it means the assumption a formal proof would rely on doesn't even match how the testbench itself drives the design in simulation — undermining confidence in both the formal result and the simulation runs.
Quick Check
Q: Why would a violated assume in simulation be worth investigating, rather than just being expected behavior?
Show Answer
Because the same property is likely also being handed to a formal tool as a constraint on its input space. If simulation itself violates that constraint, the formal analysis built on top of it is reasoning about inputs that don't actually reflect how the real testbench behaves — a mismatch worth catching early.
Using the Same Property With All Three
Rather than writing the same temporal pattern three separate times, declare it once as a named property and reuse it across statement types as needed:
property p_check;
@(posedge clk) disable iff (!rst_n) req |=> ack;
endproperty
// Check it in simulation
assert property (p_check);
// Track how often it's actually exercised
cover property (p_check);
Both statements reference the exact same underlying temporal logic — there's no risk of the assert-side and cover-side definitions drifting apart, since there's only one property definition to maintain.
Where Is This Used?
Formal verification teams frequently take properties already written for simulation and add assume statements around the environment's own input constraints — reusing the exact same property declarations across both simulation and formal, rather than rewriting the temporal logic separately for each flow. This dual-use is a major reason SVA properties are written as standalone, named declarations instead of being inlined directly into a single assert statement.
Common Beginner Mistakes
Mistake #1: Assuming assume does nothing in simulation
It's typically checked in simulation too, not just treated as inert documentation for formal tools. Why? A violated assume in simulation is a genuine signal that the testbench doesn't honor an assumption a formal proof is relying on — worth investigating, not ignoring.
Mistake #2: Treating cover property as dependent on assert
A property can be covered without ever being asserted, and asserted without ever being covered — they're entirely independent statement types. Why? Some properties are purely tracked for coverage purposes with no corresponding correctness check at all, and vice versa.
Mistake #3: Confusing "never failed" with "actually exercised"
As the note above explains, these are genuinely different things. Why? An assertion that's never had the chance to fail (because its antecedent never fired) provides zero actual verification value, even though it reports nothing but passes — only cover property can confirm the scenario was genuinely exercised.
Mistake #4: Writing the same temporal logic three separate times
Duplicating a property's logic across separate assert, assume, and cover statements risks the copies drifting out of sync if only one is ever updated. Why? Declaring the property once and referencing it from each statement type guarantees they always stay perfectly consistent with each other.
Practice Exercise
Challenge: Predict assert vs cover on the Same Trace
A property p_check: req |=> ack is checked against three separate occurrences of req during a test. Two of them are correctly followed by ack; the third is not. What would assert property(p_check) report, and what would cover property(p_check) report?
Hint
One of these two statement types cares about the failure; the other only cares about counting successes.
Solution
assert property(p_check) reports one failure — specifically, the occurrence where ack didn't follow req as required. cover property(p_check) reports a coverage count of 2 — the two occurrences where the property actually succeeded — completely independent of the fact that a third occurrence failed. The failed occurrence simply doesn't count toward coverage; it isn't treated as a negative event by cover at all.
Summary
In this tutorial, you learned:
assert propertychecks that a property holds and reports a failure when it doesn'tcover propertytracks how many times a property actually succeeded, independent of anyasserton the same propertyassume propertyis a constraint on input generation for formal tools, but is typically still checked (and can still fail) in simulation- A property that never fails isn't necessarily meaningful — if its antecedent never fires, every check is vacuously true, and
cover propertyis what actually reveals that - Declaring a property once and reusing it across
assert,assume, andcoverstatements keeps simulation checking, formal constraints, and coverage tracking permanently consistent with each other
Verilog's general-purpose always block can model many kinds of hardware. It also models algorithmic behavior, such as implicit state machines spanning multiple cycles, and is used in testbenches for clock generation and repeated verification processes. SystemVerilog adds three special-purpose blocks, always_comb, always_latch and always_ff, that state exactly which kind of hardware you mean. Simulators, synthesis tools and lint checkers can then verify that your code matches that intent.
8 min read | Intermediate Level
What You'll Learn
- Why the general-purpose
alwaysblock leaves tools guessing about your intent - How
always_combinfers its sensitivity list, and how that improves on@* - When to use
always_latchandalways_ff, and the rules each one enforces - The coding mistakes these blocks help you catch
Why do we need a special always block?
A synthesis tool cannot simply execute an always block's statements. It must also work out whether the block describes combinational logic, a latch or flip-flops, by analyzing its statements and event controls. In the example below, combinational and sequential coding styles are mixed in the same always block.
module my_design (
input logic clk,
input logic reset_n, // Active-low reset
input logic d1,
input logic d2,
output logic q
);
logic temp;
always @(posedge clk) begin
if (!reset_n)
q <= 0;
else begin
// Blocking assignment (combinational style) mixed inside sequential block
temp = d1 & d2;
q <= temp | (q << 1);
// Incrementing q again creates ambiguity in synthesis
q = q + 1;
end
end
endmodule
The syntax and semantics are legal, so there are no compile or run-time errors in simulation:
xcelium> run xmsim: *W,RNQUIE: Simulation is complete. xcelium> exit
Synthesis tools, however, report errors and warnings:
# Siemens Precision #------------------- # Info: [44522]: Root Module my_design: Pre-processing... # Error: [46778]: "/home/runner/design.sv", line 21: Blocking assignment on a non-blocking signal(q). Skipping compilation of this module. Continuing ... # Warning: [45383]: Module my_design: This module cannot be compiled because it contains non-RTL constructs. # Info: [44536]: No modules were compiled in this run of RTLC, please check the logs for blackboxes or non-rtl constructs in the design. # Info: [44513]: Overall running time for compilation: 1.0 secs. # Error: [46259]: Design compilation failed, unsupported or non-rtl constructs detected in the following modules : # Info: [40000]: my_design # Info: [40000]: Please check the log for details pertaining to unsupported or non-rtl construct(s) # Error: [685]: Unable to elaborate design work.my_design in verilog.
[Synth 8-6157] synthesizing module 'my_design' [Synth 8-6090] variable 'q' is written by both blocking and non-blocking assignments, entire logic could be removed
The design simulated "fine" but cannot be built. SystemVerilog addresses this gap by adding hardware-specific procedural blocks that make intent explicit. The new blocks do not make the code above legal. They give every tool in the flow the same statement of intent, so problems like this are flagged consistently and earlier.
Syntax
always_comb begin // combinational logic, no sensitivity list
// blocking assignments (=)
end
always_latch begin // level-sensitive latch, no sensitivity list
if (enable) q = d;
end
always_ff @(posedge clk or negedge rst_n) begin // flip-flops, explicit edge events
// non-blocking assignments (<=)
end
always_comb | always_latch | always_ff | |
|---|---|---|---|
| Intended hardware | Combinational logic | Latches | Flip-flops |
| Sensitivity list | Inferred automatically | Inferred automatically | Written explicitly, one event control at the start |
| Runs once at time 0? | Yes | Yes | No, only on its events |
| Delays or waits inside? | Not allowed | Not allowed | Only the single event control at the start |
| Variables written here driven elsewhere? | Not allowed | Not allowed | Not allowed |
always_comb
The always_comb block states that the logic is combinational. You don't write a sensitivity list: the tool infers it from every signal the block reads. Temporary variables that are written before they are read inside the block are left out.
module alu_4_bit (
input logic [3:0] a,
input logic [3:0] b,
input logic [1:0] op_code,
output logic [3:0] result
);
// This is a combinational always block
always_comb begin
case (op_code)
2'b00: begin
result = a + b; // Addition
end
2'b01: begin
result = a - b; // Subtraction
end
2'b10: begin
result = a & b; // Bitwise AND
end
2'b11: begin
result = a | b; // Bitwise OR
end
endcase
end
endmodule
All four values of op_code are covered, so result is assigned on every path and the block is purely combinational. If one case item were missing, result would have to hold its old value for that code, which means a latch. Tools flag that as a mismatch with the always_comb intent.
Sensitivity to signals read inside functions
In Verilog, always @* includes the signals read directly in the block, including expressions passed as function arguments. It does not include signals that a called function reads internally, such as a module-level variable used inside the function body. So all signals a function uses must be passed in as arguments. If a function's signal usage changes, its definition and every call site must be updated together.
logic a, b, en, z;
// 'en' is read inside the function body; it is not passed as an argument
function automatic logic and_en (input logic x, y);
return x & y & en;
endfunction
always @* begin // sensitive to a and b only: a change on en is missed
z = and_en(a, b);
end
When en changes while a and b stay the same, the @* block does not wake up, and z keeps a stale value in simulation. Synthesis builds the correct AND gate anyway, so simulation and gates disagree. SystemVerilog's always_comb removes this limitation. It is sensitive to signals read directly in the block and to signals read inside the functions it calls:
always_comb begin // sensitive to a, b and en (read inside the function)
z = and_en(a, b);
end
always_comb adds two more guarantees that always @* lacks:
- It runs once at time zero, after all
initialandalwaysblocks have started. Its outputs therefore reflect the inputs from the start. Analways @*block waits for an input to change, so its outputs can stay X if the inputs never change. - Single driver: variables on the left-hand side cannot be written by any other process. This prevents shared variables that would break the intended combinational behavior.
Quick Check
Q: A block assigns y = sel ? a : b;. Its inputs are set by an initial block at time 0 and never change afterwards. Why might always @* leave y at X while always_comb does not?
Show Answer
If the initial block assigns the inputs before the @* block has started waiting, the change is missed and the block never runs. always_comb runs once at time zero regardless, so y is computed from the initial values.
always_latch
The always_latch block is for logic that is meant to be a latch. It follows the same rules as always_comb: the sensitivity list is inferred, it runs once at time zero, and the variables it assigns cannot be driven by any other process.
module data_selector_with_latch (
input wire a_in,
input wire b_in,
input wire sel,
input wire enable,
output reg data_out
);
// This is the combinational part of the logic, a 2-to-1 mux
wire mux_out;
assign mux_out = sel ? a_in : b_in;
// This is the sequential part (the latch) that will hold the value
always_latch begin
if (enable) begin
data_out = mux_out;
end
end
endmodule
The difference from always_comb is the intent. Tools know you want a storage element, so they apply different checks. In latch logic, it is fine for an output not to be assigned on every path: data_out simply holds its value while enable is low. Written with always_comb, the same code would get a warning or error for the missing else, because combinational logic must define every output for every input.
always_ff
The always_ff block models synthesizable sequential logic such as flip-flops. Unlike always_comb and always_latch, it requires an explicit sensitivity list. The signals you list decide whether set and reset are synchronous or asynchronous.
module sync_counter_3bit (
input wire clk,
input wire reset_n, // Active-low reset
output reg [2:0] count
);
// This is the sequential always block, triggered on a clock edge
always_ff @(posedge clk or negedge reset_n) begin
if (!reset_n) begin
// Asynchronous reset: sets the count to 0 when reset_n is low
count <= 3'b000;
end else begin
// On the positive edge of the clock, increment the count
count <= count + 1'b1;
end
end
endmodule
Because reset_n is in the event list, the reset takes effect as soon as it falls, without waiting for a clock edge. That makes it asynchronous, despite the module name. A synchronous reset would list only posedge clk. The counter wraps from 7 back to 0.
always_ff enforces stricter rules to stay consistent with synthesis:
- It must contain exactly one event control, at the start of the block, and no other delays or waits.
- Variables assigned in it cannot be written by any other process.
- Synthesis tools also expect every signal in the event list to be qualified with
posedgeornegedge, and tools may warn if the body does not follow flip-flop coding practice.
Where are these blocks used?
Most RTL coding guidelines in industry now require always_ff for every flip-flop and always_comb for every block of combinational logic, and forbid plain always in synthesizable code. Lint and synthesis tools then flag accidental latches and multiple drivers automatically, which catches many bugs before simulation even starts.
Using These Blocks in Verification
These blocks describe hardware, so testbench stimulus still uses initial, always and forever. always_comb is still handy in verification code for small combinational models, for example deriving an expected parity bit inside an interface or a reference model. Its time-zero evaluation and complete sensitivity list keep the model in step with the DUT from the first cycle.
Common Beginner Mistakes
Mistake #1: Incomplete assignments in always_comb
Wrong: always_comb if (en) y = a;
Right: always_comb begin y = '0; if (en) y = a; end
Why? When en is 0, y must keep its old value, which needs a latch. That contradicts always_comb, and tools report it. Assign a default at the top of the block. If you really want a latch, use always_latch.
Mistake #2: Driving one variable from two blocks
Assigning state in two different always_ff blocks, such as one for reset and one for normal operation, is a compile error. Why? Each variable written by always_comb, always_latch or always_ff must have exactly one driving process. With plain always, this mistake would only show up as a race in simulation or as a synthesis error.
Mistake #3: A level-sensitive event list in always_ff
Wrong: always_ff @(clk or rst_n)
Right: always_ff @(posedge clk or negedge rst_n)
Why? Flip-flops respond to edges. Without posedge or negedge, synthesis cannot map the block to flip-flops and reports an error.
Practice Exercise
Challenge: Counter with enable
Write a 4-bit counter with an active-low asynchronous reset rst_n and an enable en. Compute the next count value in an always_comb block and register it in an always_ff block.
Hint
Give the next-value signal a default of "hold the current count" in always_comb, so it is assigned on every path. The always_ff block only resets or copies the next value.
Solution
module counter_en (
input logic clk,
input logic rst_n,
input logic en,
output logic [3:0] count
);
logic [3:0] count_next;
// Next-state logic: purely combinational
always_comb begin
count_next = count; // default: hold (no latch)
if (en)
count_next = count + 4'd1; // increment when enabled
end
// State register: flip-flops with asynchronous active-low reset
always_ff @(posedge clk or negedge rst_n) begin
if (!rst_n) count <= '0;
else count <= count_next;
end
endmodule
Each variable has exactly one driver: count_next is driven by always_comb and count by always_ff. This split between next-state logic and the register is the standard RTL style for counters and FSMs.
Summary
In this tutorial, you learned:
always_comb,always_latchandalways_ffstate your hardware intent so tools can check italways_combinfers a complete sensitivity list, including signals read inside called functions, which@*missesalways_combandalways_latchboth run once at time zero;always_ffruns only on its edge events- Variables written in any of the three blocks cannot be driven by another process
always_fftakes exactly one event control at the start, with edge-qualified signals for synthesis- Assign defaults in
always_combto avoid unintended latches
A single coverpoint tells you whether a variable took a particular value at some point during the test. It says nothing about which values happened together. Cross coverage fills that gap. It tracks combinations of bins across two or more coverpoints, which is exactly what you need to catch corner cases that only appear when several conditions line up at once.
8 min read | Intermediate Level
What You'll Learn
- What cross coverage measures and how its automatic bins are created
- The syntax of a
crossstatement and the rules for what it can contain - How to build custom cross bins with
binsofand useintersectcorrectly - How
illegal_binsandignore_binschange the cross coverage total
What Is Cross Coverage?
Cross coverage observes the combination of states between two or more coverpoints. Instead of asking "did master_id ever equal 2?" it asks "did master_id equal 2 while slave_id equalled 3?" This is essential for verifying interactions such as every opcode with every addressing mode, or every command type with every address region.
Syntax
Cross coverage is declared with the cross keyword inside a covergroup:
[label :] cross item1, item2 [, itemN] [iff (expression)] [{
bins bin_name = select_expression;
ignore_bins bin_name = select_expression;
illegal_bins bin_name = select_expression;
}];
- label (optional): names the cross and creates a scope for its custom bins
- item1, item2 ... (required, two or more): coverpoint names, or plain variables in the same covergroup
iff (expression)(optional): the cross is sampled only when the expression is true- body (optional): user-defined, ignored and illegal cross bins
Some rules to remember:
- When a plain variable is listed in a
cross, SystemVerilog creates an implicit coverpoint for it with automatic bins. - An expression such as
a + bcannot be crossed directly. Define it as a named coverpoint first, then cross the coverpoint. - All items in a
crossmust belong to the same covergroup.
A Basic Cross Coverage Example
Imagine a system where different masters can initiate transactions with different slaves. Individual coverpoints on master_id and slave_id are useful, but they do not tell you whether master 0 ever actually talked to slave 1. A cross answers exactly that:
covergroup master_slave_interaction @(posedge clk);
master_id_cp: coverpoint master_id {
bins master0 = {0};
bins master1 = {1};
bins master2 = {2};
bins master3 = {3};
}
slave_id_cp: coverpoint slave_id {
bins slave0 = {0};
bins slave1 = {1};
bins slave2 = {2};
bins slave3 = {3};
}
ms_cross: cross master_id_cp, slave_id_cp; // Cross coverage declaration
endgroup
ms_cross automatically creates one cross product bin for every combination of the two coverpoints' bins. Since both coverpoints have 4 bins, the cross produces 4 x 4 = 16 bins: <master0,slave0>, <master0,slave1>, and so on up to <master3,slave3>. Each bin counts one specific master-slave interaction.
The label before the colon becomes the cross's name and the scope for any custom bins. If you omit it, the tool generates a name for reporting, but that name cannot be referenced in your code.
Label every cross. It makes coverage reports readable and lets you refer to the cross from coverage options and custom bins.
Quick Check
Q: If master_id_cp had 5 bins and slave_id_cp had 3 bins, how many automatic cross bins would the cross create?
Show Answer
15. The number of automatic cross bins is the product of the participating coverpoints' bin counts, 5 x 3 in this case.
Selecting Cross Products with binsof and intersect
Custom cross bins are built from select expressions. The binsof construct picks bins from one coverpoint, and the optional intersect clause narrows that pick to bins whose values overlap a given value or range list in braces.
| Select expression | Selects cross products where... |
|---|---|
binsof(cp.b) | bin b of cp is part of the combination |
binsof(cp) intersect {[0:1]} | the bin of cp contains at least one value in 0 to 1 |
!binsof(cp) intersect {[0:1]} | the bin of cp contains no value in 0 to 1 |
sel1 && sel2 | both selections are true |
sel1 || sel2 | either selection is true |
The right-hand side of intersect is always a brace-enclosed value or range list, never another binsof(). To combine conditions on two different coverpoints, join two select expressions with && or ||.
Defining User-Defined Cross Coverage Bins
User-defined bins group one or more cross products under a single name. Say you care about master 0 accessing slave 1, and separately about any master accessing slave 3:
covergroup master_slave_interaction_refined @(posedge clk);
master_id_cp: coverpoint master_id {
bins master0 = {0};
bins master1 = {1};
bins master2 = {2};
bins master3 = {3};
}
slave_id_cp: coverpoint slave_id {
bins slave0 = {0};
bins slave1 = {1};
bins slave2 = {2};
bins slave3 = {3};
}
ms_cross: cross master_id_cp, slave_id_cp {
bins master0_slave1 = binsof(master_id_cp.master0) && binsof(slave_id_cp.slave1);
bins any_master_slave3 = binsof(slave_id_cp.slave3);
// Selects : 4 cross products grouped into one bin
}
endgroup
- master0_slave1 combines two
binsofselections with&&, so it matches only the single product<master0,slave1>. - any_master_slave3 uses
binsof(slave_id_cp.slave3)on its own. Because no condition is placed on master_id_cp, every master paired with slave 3 is selected. The bin is covered as soon as any one of those four combinations is hit.
Here is the same idea written with intersect, to cover only the low-numbered masters talking to slave 3:
ms_cross: cross master_id_cp, slave_id_cp {
// master bins whose values overlap 0..1 (master0, master1), paired with slave3
bins low_masters_slave3 = binsof(master_id_cp) intersect {[0:1]} &&
binsof(slave_id_cp) intersect {3};
}
Any cross product not included in a user-defined bin still gets its own automatic bin. With the two bins in the refined example above, the cross reports 2 user-defined bins plus 11 automatic bins (16 - 1 - 4).
Where Is Cross Coverage Used?
Cross coverage is a natural fit for protocol verification: confirming every command type was issued to every address region, every burst length was used with every data width, or every opcode was executed in every privilege mode. It is also used in stress testing to confirm that high-traffic or boundary combinations were hit, not just each field in isolation.
Specifying Illegal and Ignore Cross Products
Not every combination is valid or relevant. Two special bin types handle these cases:
illegal_bins: combinations that should never occur. Hitting one produces a run-time error, and these products are excluded from the coverage total.ignore_bins: combinations that are valid but not part of your coverage goals. They are excluded from the coverage total.
covergroup master_slave_interaction_with_exceptions @(posedge clk);
...
ms_cross: cross master_id_cp, slave_id_cp {
bins master0_slave1 = binsof(master_id_cp.master0) && binsof(slave_id_cp.slave1);
bins any_master_slave3 = binsof(slave_id_cp.slave3);
illegal_bins bad_master_slave_config = binsof(master_id_cp.master0) && binsof(slave_id_cp.slave0); // Master 0 should not talk to Slave 0
ignore_bins unused_master_slave_combo = binsof(master_id_cp.master3) && binsof(slave_id_cp.slave2); // Valid, but not critical to cover
}
endgroup
If master 0 accesses slave 0, the simulator reports an error. The combination of master 3 and slave 2 simply does not contribute to the coverage percentage. If a product falls into both an illegal_bins and an ignore_bins selection, it is still treated as illegal and the error is reported.
The diagram below shows how all 16 cross products of ms_cross are classified:
Quick Check
Q: In the example above, how many bins count toward the coverage percentage of ms_cross?
Show Answer
11. Out of 16 products, 1 belongs to master0_slave1, 4 to any_master_slave3, 1 is illegal and 1 is ignored. The remaining 9 become automatic bins, giving 2 user-defined + 9 automatic = 11 bins.
Cross Coverage in Design and Verification
Covergroups are a verification construct and are not synthesizable. In a testbench they are usually placed in a monitor or subscriber that samples transaction fields, which is the most common use of cross coverage.
Design engineers can still use cross coverage to capture design intent, for example crossing FSM state with an input request to confirm every request was seen in every state. A covergroup can be declared inside an RTL module or interface, or attached with bind, as long as it is excluded from synthesis.
`ifndef SYNTHESIS
covergroup fsm_cg @(posedge clk);
state_cp : coverpoint state; // enum-typed FSM state
req_cp : coverpoint req;
state_x_req : cross state_cp, req_cp;
endgroup
fsm_cg fsm_cg_inst = new();
`endif
Leaving a covergroup outside a synthesis guard can cause errors or warnings in synthesis tools. Always wrap design-embedded coverage in `ifndef SYNTHESIS or keep it in a separate bind file.
Design-Side Coverage in Practice
RTL designers often add small covergroups or cover property statements next to complex control logic such as arbiters and FIFO controllers. Crossing arbiter grant with requester count, for example, shows whether the fairness logic was exercised under contention, not just in idle conditions.
Common Beginner Mistakes
Mistake #1: Trying to cross an expression directly
cross only accepts coverpoint names or plain variables. Why? To cross something like mode + cfg, first define a named coverpoint for the expression, then reference that coverpoint in the cross.
Mistake #2: Expecting intersect to select only bins fully inside the range
binsof(cp) intersect {3} selects every bin of cp that contains the value 3, even if the bin also holds other values. A bin defined as {[0:7]} is selected. Why? intersect checks for overlap, not containment. If you need exact selection, refer to the bin directly with binsof(cp.bin_name).
Mistake #3: Assuming invalid combinations are excluded automatically
A cross creates automatic bins for every combination, whether or not it makes sense for the design. Why? The tool has no knowledge of your protocol rules. Unreachable combinations must be marked with illegal_bins or ignore_bins, otherwise coverage can never reach 100%.
Practice Exercise
Challenge: Cross Two 2-Bin Coverpoints
Given a coverpoint cp_dir with 2 bins (read, write) and a coverpoint cp_region with 2 bins (low, high), write a labeled cross between them. How many automatic cross bins does it create? As a bonus, add a user-defined bin that collects all writes using intersect.
Hint
Follow the label: cross cp1, cp2; pattern and multiply the bin counts. For the bonus, write is the bin holding the value 1.
Solution
covergroup cg @ (posedge clk);
cp_dir : coverpoint dir {
bins read = {0};
bins write = {1};
}
cp_region : coverpoint region {
bins low = {0};
bins high = {1};
}
dir_region_cross : cross cp_dir, cp_region;
endgroup
2 bins x 2 bins = 4 automatic cross bins: <read,low>, <read,high>, <write,low> and <write,high>.
Bonus: give the cross a body with bins all_writes = binsof(cp_dir) intersect {1};. It groups <write,low> and <write,high> into one bin, leaving 2 automatic bins for the reads.
Summary
In this tutorial, you learned:
- Cross coverage tracks combinations of bins across two or more coverpoints, not each one in isolation
- A
crossaccepts coverpoints or plain variables from the same covergroup; expressions need their own coverpoint first - The number of automatic cross bins is the product of the participating coverpoints' bin counts
binsofselects bins of one coverpoint, andintersectnarrows that selection to bins overlapping a value or range list in braces- Conditions on different coverpoints are combined with
&&and||; products not in any user-defined bin still get automatic bins illegal_binsflag combinations that must never happen;ignore_binsdrop valid but irrelevant ones; both are excluded from the coverage total- Covergroups are not synthesizable, but designers can embed cross coverage in RTL behind a synthesis guard
To manage the mutability of class properties, SystemVerilog provides the const keyword, allowing properties to be made read-only. Due to the dynamic nature of class objects, this manifests in two distinct forms: global constant class properties and instance constant class properties.
9 min read | Intermediate Level
What You'll Learn
- The difference between a global constant class property and an instance constant class property
- Why global constants are commonly declared
static, and why instance constants never can be - Why an instance constant can only ever be assigned inside the constructor
- What happens if you try to assign either kind of constant from outside its class
Global Constant Class Properties
A global constant class property is a read-only data member assigned its value as part of its own declaration. Like other const variables in SystemVerilog, its value can't be changed anywhere else after that initial declaration. A common practice is to declare global constants static as well, meaning every object of the class shares the exact same constant value:
class Jumbo_Packet;
// max_size is a global constant, same for all Jumbo_Packet instances
const int max_size = 5 * 10;
byte payload [];
function new(int size);
// payload size is limited by the global constant max_size
payload = new[ size > max_size ? max_size : size ];
endfunction
endclass
module tb;
Jumbo_Packet m_pkt;
initial begin
m_pkt = new(100);
$display("size=%d", m_pkt.payload.size());
end
endmodule
Output
xcelium> run size= 50 xmsim: *W,RNQUIE: Simulation is complete.
max_size evaluates to 50 at declaration time. Since the requested size (100) exceeds it, the constructor clamps payload's actual size down to max_size instead.
Quick Check
Q: If a second object were created with new(30) instead, what would its payload size be?
Show Answer
30. Since 30 doesn't exceed max_size (50), the ternary in the constructor takes the requested size as-is, with no clamping needed.
Instance Constant Class Properties
An instance constant class property doesn't include an initial value in its declaration — only the const qualifier. It can be assigned a value exactly once at run time, and that assignment must happen inside the class's own constructor. Unlike global constants, instance constants can never be declared static, since that would prevent them from being assigned per-object inside the constructor at all — their entire purpose is to differ from one object to the next:
class Big_Packet;
// size is an instance constant, determined at object creation
const int size;
byte payload [];
function new();
// The instance constant 'size' is assigned its value once in the constructor
size = $urandom % 10;
payload = new[ size ];
endfunction
endclass
module tb;
Big_Packet m_pkt;
initial begin
m_pkt = new();
$display("size=%d", m_pkt.payload.size());
// This will result in a compilation error
// xmvlog: *E,CLSCON (testbench.sv,23|13): Instance constant class properties cannot be assigned outside of a constructor.
// m_pkt.size = 50;
end
endmodule
Output
xcelium> run size= 4 xmsim: *W,RNQUIE: Simulation is complete.
size is assigned once, inside new(), and its exact value here depends on the simulation's random seed — a different seed would produce a different (but still fixed, once assigned) value for that specific object.
Here's that commented-out line demonstrated directly, as its own standalone example:
class Big_Packet;
const int size;
byte payload [];
function new();
size = $urandom % 10;
payload = new[ size ];
endfunction
endclass
module tb;
Big_Packet m_pkt;
initial begin
m_pkt = new();
m_pkt.size = 50; // Attempting to reassign the instance constant from outside its constructor
end
endmodule
Output
xmvlog: *E,CLSCON (testbench.sv,23|13): Instance constant class properties cannot be assigned outside of a constructor.
Quick Check
Q: Does m_pkt.size = 50; fail at compile time or run time?
Show Answer
Compile time — note the ncvlog/xmvlog prefix on the error, which is the compiler's own analysis stage, not the simulator actually running anything. The restriction is checked before simulation ever starts.
Difference Between Global and Instance
| Global constant | Instance constant | |
|---|---|---|
| Initial value | Given at declaration | None at declaration |
| When assigned | Once, at declaration | Once, inside the constructor |
| Can be static | Yes | No |
| Value across objects | Same for every instance | Can differ per instance |
Where Are Const Class Properties Used?
A global constant fits a protocol-wide fixed limit that's genuinely the same for every object — a maximum burst length, or a maximum payload size shared across every transaction. An instance constant fits a value that's fixed once an object is created but is meant to vary between objects — like a uniquely assigned (and then immutable) transaction ID.
Common Beginner Mistakes
Mistake #1: Trying to assign an instance constant outside its constructor
As the standalone CLSCON example shows, this is always a compile-time error, no matter where outside the constructor the attempt happens. Why? An instance constant's entire point is to be fixed exactly once, at construction — allowing any later assignment would defeat that guarantee entirely.
Mistake #2: Declaring an instance constant as static
This isn't allowed. Why? static means one shared value across every object, but an instance constant exists specifically to let each object have its own distinct value, assigned individually inside its own constructor call — the two ideas are directly incompatible.
Mistake #3: Confusing global and instance constants' assignment timing
A global constant's value is fixed once for the entire class, computed at declaration — it can't be recalculated per object the way an instance constant can. Why? If a value genuinely needs to vary between objects (like a random per-object ID), it has to be an instance constant, assigned in the constructor — a global constant simply can't do that.
Mistake #4: Assuming a const property without static means "per instance" automatically
A non-static const property still needs to actually declare an initial value or be assigned in the constructor to be either a global or instance constant, respectively — the static keyword itself isn't what determines which kind it is. Why? The real distinguishing factor is whether the value is given at declaration (global) or left for the constructor to assign (instance), not the presence or absence of static alone — though static is only ever legal on the global kind.
Practice Exercise
Challenge: Combine Both Kinds of Constant
Write a class Transaction with a global constant static const int MAX_ID = 100; and an instance constant const int id;. In the constructor, accept a requested_id argument, and assign id to whichever is smaller: requested_id or MAX_ID. Create two objects — one with a requested ID under the limit, one over it — and display both.
Hint
The clamping logic here is the same ternary pattern used in the Jumbo_Packet example — just applied to an instance constant instead of a plain property.
Solution
class Transaction;
static const int MAX_ID = 100;
const int id;
function new (int requested_id);
id = (requested_id > MAX_ID) ? MAX_ID : requested_id;
endfunction
endclass
module tb;
initial begin
Transaction t1 = new (50);
Transaction t2 = new (150);
$display ("t1.id=%0d, t2.id=%0d", t1.id, t2.id);
end
endmodule
This prints t1.id=50, t2.id=100. t1's requested ID (50) is under the shared limit, so it's used as-is; t2's requested ID (150) exceeds MAX_ID, so it's clamped down to 100 — each object's id is fixed permanently the moment its constructor finishes.
Summary
In this tutorial, you learned:
- A global constant class property is assigned its value at declaration, and typically declared
staticso every object shares it - An instance constant class property has no initial value at declaration, and is assigned exactly once, inside the constructor — letting each object have its own distinct value
- An instance constant can never be declared
static, since that would conflict with assigning it per-object - Assigning either kind of constant outside its allowed point — declaration for global, constructor for instance — is a compile-time error, not a run-time one
In Verilog, a `define macro is a powerful feature that allows for global text substitution in your code. It is a compiler directive that enables developers to define reusable code snippets or constants that can be easily referenced throughout the design.
`define WIDTH 16 // Define macro WIDTH, substitute 16
`define EN_ADDR // Define macro EN_ADDR, substitute nothing
wire [`WIDTH-1:0] addr; // Declares a 16-bit wire
`ifdef EN_ADDR // Instantiate an adder if EN_ADDR macro is defined
genvar i;
generate
// Code to instantiate an adder
endgenerate
`endif
Read more on Verilog `define Macros !
Quiz
No quiz questions available for this article.