16 Constrain addr in range. Collect coverage
Sep 26, 2017 |
Constraint, Coverage
Use constraints to restrict an address and range to be within a memory.Use coverage to collect results.
//This is the first episode released in a while. The video is sped up, which hopefully is better for consumption (even if it results in a funny voice). The presentation is also less rehearsed than previous episodes, so shows some trial and error at the end.
//Choosing a random location and amount of data to transfer from a memory.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module top;
parameter MEMORY_SIZE = 100;
class class1;
rand logic [($clog2(MEMORY_SIZE)-1):0] addr;
rand logic [($clog2(MEMORY_SIZE)-1):0] xfer_num;
rand logic [($clog2(MEMORY_SIZE)-1):0] burst_num;
constraint c_addr_range { addr>=0; addr<MEMORY_SIZE; }
constraint c_xfer_num { xfer_num >0; xfer_num <=MEMORY_SIZE; }
constraint c_burst_num { burst_num>0; burst_num<=MEMORY_SIZE; }
constraint c_total_xfer_size { (xfer_num*burst_num)<=MEMORY_SIZE; }
// constraint c_sub_100 { (addr+amount_to_transfer()-1)<=MEMORY_SIZE; }
function int amount_to_transfer();
return(xfer_num*burst_num);
endfunction
covergroup my_covergroup;
option.per_instance = 1;
coverpoint addr;
endgroup
function new();
my_covergroup=new;
endfunction
function void post_randomize();
$display("***** addr:%0d\t xfer_num:%0d\t burst_num:%0d. coverage:%3.2f%%",addr,xfer_num,burst_num,my_covergroup.get_inst_coverage());
as_all_in_range : assert ( (addr + (xfer_num*burst_num)-1) <= MEMORY_SIZE ) else begin
$display("ERROR. OUT OF RANGE.");
end
endfunction
endclass
class1 my_class1;
initial begin
my_class1=new();
$display("Choose a start address, and an amount of data to transfer. Indicate location in memory of size %0d locations. (%0d bits are needed to address memory of size %0d locations.) ", MEMORY_SIZE, $clog2(MEMORY_SIZE), MEMORY_SIZE);
repeat (20) begin
void'(my_class1.randomize());
my_class1.my_covergroup.sample();
end
$finish;
end
endmodule