SystemVerilog -- 10.2 SystemVerilog Coverpoint Bins
SystemVerilog Coverpoint Bins
Usage
coverpoint 用于在 covergroup 中指定要进行覆盖率收集统计收集的目标的变量。它记录单个变量或表达式的观测值。
- coverpoint后面跟变量名或表达式,用于指定要收集覆盖率的目标。
- 可以使用bins关键字手动定义覆盖仓(bins),记录变量在不同值域范围内被采样的次数。
- 也可以使用option.auto_bin_max自动创建指定数量的覆盖仓,将变量值域平均分配。
coverpoint mode {
// Manually create a separate bin for each value
bins zero = {0};
bins one = {1};
// Allow SystemVerilog to automatically create separate bins for each value
// Values from 0 to maximum possible value is split into separate bins
bins range[] = {[0:$]};
// Create automatic bins for both the given ranges
bins c[] = {[2:3], [5:7]};
// Use fixed number of automatic bins. Entire ranges is broken up into 4 bins
bins range[4] = {[0:$]};
// If the number of bins cannot be equally divided for the given range, then
// the last bin will include remaining items; Here there are 13 values to be
// distributed into 4 bins which yields:
bins range[4] = {[1:10], 1, 3, 6};
// A single bin to store all other values that don't belong to any other bin
bins others = default;
}
Examples
module tb;
bit [2:0] mode;
// This covergroup does not get sample automatically because the sample event is missing in declaration
covergroup cg;
cooverpoint mode {
bins one = {1};
bins five = {5};
}
endgroup
// Stimulus : Simply randomize mode to have different values and manually sample each time
initial begin
cg cg_inst = new ();
for (int i = 0; i < 5; i++) begin
#10 mode = $random;
$display ("[%0t] mode = 0x%0h", $time, mode);
cg_inst.sample ();
end
$display ("Coverage = %0.2f %%", cg_inst.get_inst_coverage());
end
endmodule
模拟日志
ncsim> run
[10] mode = 0x4
[20] mode = 0x1
[30] mode = 0x1
[40] mode = 0x3
[50] mode = 0x5
Coverage = 100.00 %
ncsim: *W,RNQUIE: Simulation is complete.
Automatic Bins
covergroup cg;
coverpoint mode {
// Declares a separate bin for each values -> Here there will 8 bins
bins range[] = {[0:$]};
}
endgroup
模拟日志
ncsim> run
[10] mode = 0x4
[20] mode = 0x1
[30] mode = 0x1
[40] mode = 0x3
[50] mode = 0x5
Coverage = 50.00 %
ncsim: *W,RNQUIE: Simulation is complete.
Fixed Number of automatic bins
covergroup cg;
coverpoint mode {
// Declares 4 bins for the total range of 8 values
// So bib0->[0:1] bib1->[2:3] bib2->[4:5] bib3->[6:7]
bins range[4] = {[0:$]};
}
endgroup
mode
从未获得 6 或 7 的值,因此 bin3 不会被命中。但是所有其它 bins 都被 hit,因此覆盖率为 75%。
模拟日志
ncsim> run
[10] mode = 0x4
[20] mode = 0x1
[30] mode = 0x1
[40] mode = 0x3
[50] mode = 0x5
Coverage = 75.00 %
ncsim: *W,RNQUIE: Simulation is complete.
Split fixed number of bins between a given range
covergroup cg;
coverpoint mode {
// defines 3 bins
// Two bins for values from 1:4, and one bin for value 7
// bin1->[1,2] bin2->[3:4 bin3->7
bins range[3] = {[1:4], 7};
}
endgroup
只有 2/3 的 bin s被 hit,因此覆盖率为 66.7%。具体来说, bin1 和 bin2 被 hit 是因为对 mode
的采样分别为 1 和 [3,4]。
模拟日志
ncsim> run
[10] mode = 0x4
[20] mode = 0x1
[30] mode = 0x1
[40] mode = 0x3
[50] mode = 0x5
Coverage = 66.67 %
ncsim: *W,RNQUIE: Simulation is complete.