Cross coverage is a mechanism in SystemVerilog used to analyze how multiple coverage points interact with each other. It is particularly useful when you want to check combinations of values across different variables. For example, if you have two variables, opcode and status, cross coverage ensures you verify all possible pairs of their values.
By leveraging cross coverage, you can detect whether your simulation exercises specific combinations of parameters, which may represent critical scenarios for the design under test.
Defining Cross Coverage in SystemVerilog
Cross coverage is typically defined within a covergroup. Here’s a basic example:
covergroup cg;
coverpoint opcode;
coverpoint status;
cross opcode, status;
endgroup
In this snippet:
opcodeandstatusare coverpoints, capturing the individual values taken by their respective variables.- The
crossstatement combines these coverpoints, enabling the tool to track coverage for every(opcode, status)pair.
Benefits of Cross Coverage
Cross coverage is critical for uncovering:
- Corner Cases: Situations where specific combinations of values may reveal hidden bugs.
- Design Deficiencies: Ensuring interactions between subsystems are adequately tested.
- Test Completeness: Gauging whether a testbench exercises all meaningful scenarios.
Understanding binsof in Coverage
The binsof construct in SystemVerilog is used to reference the bins of another coverpoint or cross. This allows you to create complex coverage scenarios by directly accessing and manipulating existing bins.
Syntax and Usage
covergroup cg;
coverpoint opcode;
coverpoint status;
cross opcode, status;
coverpoint my_bins = binsof(opcode) intersect {[1:5]};
endgroup
In this example:
- The
binsof(opcode)construct retrieves bins from theopcodecoverpoint. - The
intersectoperator (explained below) narrows the bins to those in the range[1:5].
This flexibility is invaluable when you want to reuse or refine the bins of one coverpoint in another, enhancing your coverage model.
Exploring the intersect Construct
The intersect keyword is used to refine coverage bins by filtering them based on specific conditions or ranges. When used with binsof, it creates a subset of bins that meet the intersection criteria.
Example Usage
covergroup cg;
coverpoint address {
bins addr_bins[] = {[0:255]};
}
coverpoint data {
bins data_bins[] = {[0:1023]};
}
cross address, data;
coverpoint addr_data_subset = binsof(address) intersect {[100:200]};
endgroup
Here:
- The
addresscoverpoint captures address values between0and255. - The
intersect {[100:200]}clause narrows this to the subset[100:200], focusing on addresses within this range.
By combining binsof and intersect, you can tailor your coverage goals to specific areas of interest, avoiding unnecessary coverage for irrelevant cases.
Practical Applications of Cross Coverage, binsof, and intersect
- Protocol Verification: Ensuring all valid combinations of protocol fields are exercised (e.g., header type vs. payload length).
- Stress Testing: Targeting specific subsets of bins that represent critical scenarios, such as boundary conditions or high traffic.
- Debugging and Optimization: Highlighting gaps in coverage that may indicate insufficient testbench activity or overlooked corner cases.
Use of ignore_bins and illegal_bins in excluding cross product
In SystemVerilog, we can create a cross coverage between two (for example I am taking two) variables, x (4-bit) and a (2-bit), while excluding certain cross-coverage bins based on specific conditions. In the below example, cross product bins can be excluded.
covergroup cg;
// Define the 4-bit variable `x` with a range from 0 to 15
coverpoint x {
bins x_vals[] = { [0:15] };
}
// Define the 2-bit variable `a` with a range from 0 to 3
coverpoint a {
bins a_vals[] = { [0:3] };
}
cross x, a {
// Exclude bins where x = 5 and a = 0 or 1, and x = 7 and a = 2 or 3
ignore_bins exclude_x5_a01 = binsof(x) intersect {5} && binsof(a) intersect {0, 1};
ignore_bins exclude_x7_a23 = binsof(x) intersect {7} && binsof(a) intersect {2, 3};
}
endgroup
// Instantiate the covergroup
cg coverage_inst = new;
Explanation:
- Coverpoints for
xanda: These coverpoints define bins for the entire range of values forxanda. - Cross Coverage: The
cross x, astatement creates cross coverage betweenxanda. - Exclusions: The
ignore_binsstatements exclude specific bins based on your requirements:x = 5anda = 0, 1x = 7anda = 2, 3
