Similar to auto binning (where you select the number of bins and the numerical range is split among them). I want to create a set/array of bins that is not bound to the bitwidth, but instead some arbitrarily set maximum. (e.g. localparam DATA_MAX = 0xFCE0;)
I’ve tried a few methods and I think the solution is converging to using a function. However, I cannot seem to get the datatypes to work nicely.
Does anyone have some example code that would work? My initial solution tried to replicate CrossValType/CrossQueueType and assign a set of bins that way.
Example code that does NOT work.
function bins [BINS_CNT-1:0] bin_sel (int minVal, int maxVal, int bin_cnt);
int stepSize = (maxVal-minVal)/bin_cnt;
for(int i = 0; i < bin_cnt; i++) begin
if(i == bin_cnt-1) begin
bin_sel[i] = {[i*stepSize:maxVal]};
//bin_sel.push_back([i*stepSize:maxVal]);
end
else if(i == 0) begin
bin_sel[i] = {[minVal:stepSize]};
//bin_sel.push_back([minVal:stepSize]);
end
else begin
bin_sel[i] = {[i*stepSize:i*(stepSize+1)]};
//bin_sel.push_back([i*stepSize:i*(stepSize+1)]);
end
end
endfunction
However, this has one disadvantage over auto-binning as you lose the true numerical range of the bin in the bin description in the coverage tool I use.
Also i’d still like to know how it would be possible to create bins using a function. I feel like there are real use cases with that. the WITH keyword does not work for ultra-wide data buses as it becomes computationally intractable.
Thanks for the detailed reply! One question though, on this line:
bins_q.push_back(i);
This seems like a bin for a single value. I am looking for bins that contain ranges (e.g. [0:100]). Can you confirm/deny what this approach really creates?
As far as I understand ranges are not allowed, you cannot construct a queue of range expressions, only integral data types for bins in coverpoints, it would be a nice addition to find some way to provide a list ranges, as you tried already, or in the case of transition coverage a list of transitions, but I guess this is language limitation.
Hmm that is too bad. My simple solution replaces the informative bin name from describing the included numerical range per bin for auto binning to bin [0]->[BIN_CNT-1] name in the coverage tool I use.
I guess this could be avoided entirely by using a preprocessing language but that adds another layer to this whole schema.
I thought I understood your question and what you wanted but I think differently now, could you show some more details of how the bins and coverage would look like, probably enums and a function could help but I need a bit more details
You may be pushing to much into the bin construction and could be using a simple coverpoint expression instead with an array of covergroups. Here is a complete (untested) example of what I think you are trying to do:
class cg_object #(int BITWIDTH);
typedef bit [BITWIDTH-1:0] uint;
class cg_wrapper; // this is how we get around the fact that you can't have arrays of embedded covergroups in a class.
covergroup cg(uint min,max) with function sample(uint value);
option.per_instance = 1;
coverpoint value inside {[min:max]} {
bins hit = {1};
}
endgroup
function new(uint min,max);
cg =new(min,max);
cg.option.comment = $sformatf("range_%0d_%0d",min,max);
$display(cg.option.comment);
endfunction
endclass
cg_wrapper cgo[];
function new(int minVal, int maxVal, int bin_cnt);
int stepSize = (maxVal-minVal)/bin_cnt;
cgo = new[bin_cnt];
foreach(cgo[i]) begin
uint start = minVal + i*stepSize;
if (i == bin_cnt-1)
cgo[i] = new(start,maxVal);
else
cgo[i] = new(start, start + stepSize-1);
end
endfunction
function void sample(uint value);
foreach(cgo[i]) cgo[i].cg.sample(value);
endfunction
endclass
module top;
cg_object#(8) cg = new(10, 100, 4);
initial repeat (100) cg.sample($urandom_range(100));
endmodule
However, it’s a bit clunky. I find in my coverage tool the bins are out of order by default and requires a lot of clicking through to collect all comments. I think I prefer the multi cover point and the simplicity of the other solution. The workaround to the lack of ranges displayed with my original solution is to just generate a longer comment describing all of the bins, so it kinda works.