I Didn't Know Constraints Could Do That!: John Dickol Samsung Austin R&D Center
I Didn't Know Constraints Could Do That!: John Dickol Samsung Austin R&D Center
John Dickol
Samsung Austin R&D Center
6 February 2018
DVClub Europe
Introduction
SystemVerilog Constraint Techniques
Constraint Examples
Simple Complex
1; x < y; foreach(n_txns_per_slave[s]) {
0; (x + y) == z; n_txns_per_slave[s] == txn_map.sum with(
(item.index(2) == s) ? item : 0);
x == 1; if(a>b) c<d; );
x inside {[0:10]}; }
if(x==y) {
0;
} map.ranges.or(r) with (
item.addr inside
{[r.start_addr : (r.end_addr - item.size)]}
&& item.cache_type == r.cache_type
);
• Are applied only if not contradicted by other constraints with higher priority
• In general, last constraint specified has higher priority
• See SV LRM for complete list of priorities
• Good for specifying default values for UVM sequence/sequence_item
which can be overridden in higher-level sequence
task body;
class topseq extends uvm_sequence#(mytxn);
mytxn txn;
task body; Default soft constraint applies
repeat(count) begin
myseq seq;
`uvm_do(txn)
end
`uvm_do(seq)
endtask
endclass
`uvm_do_with(seq, {count == 1000;}
endtask
endclass
Inline hard constraint
overrides soft constraint
constraint c_sum_first_3 {
(a.sum with ((item.index < 3) ? item : 0)) == 10;
}
• Problem:
– Define constraints once and reuse in multiple objects
– Add additional constraints to object at runtime
• Implementation:
– Variation of hierarchical constraints: Lower-level object constrains parent object
– Define reusable constraints in “policy class” container
– Policy classes extended from common base class
– “item” variable in policy class refers to parent object
– Parent object has rand queue of policy base class
constraint c_valid {
total_txns == txn_map.sum;
}
endclass
constraint c_valid {
foreach(n_txns_per_master[m]) {
n_txns_per_master[m] == txn_map[m].sum;
}
}
endclass
constraint c_valid {
foreach(n_txns_per_slave[s]) {
n_txns_per_slave[s] == txn_map.sum with(
(item.index(2) == s) ? item : 0);
);
}
}
endclass
item.index(2) returns
Index for 2nd array dimension;
constraint c_valid {
foreach(use_master[m]) {
Count number of used
(use_master[m] == 1) == (n_txns_per_master[m] > 0);
}
masters
use_n_masters == use_master.sum with (int'(item));
foreach(use_slave[s]) {
(use_slave[s] == 1) == (n_txns_per_slave[s] > 0);
}
use_n_slaves == use_slave.sum with (int'(item))
}
endclass
Generate a total of
10000 transactions
ms_config cfg = new;
cfg.randomize with {
total_txns == 10000; Use between 2 and 4 masters
use_n_masters inside {[2:4]};
use_master[1] == 1;
use_slave[3] == 0;
} Use Master 1
• Constraint techniques:
– Soft constraints
– Unique constraints
– Array constraints (foreach, size)
– Array reduction constraints (sum, and, …)
– Reusable constraints: policy classes
Problem:
• Generate “interesting” sets of non-overlapping memory ranges
• Select memory transactions from mapped ranges
Implementation:
• mem_range class describes single range
• mem_map class has rand array of mem_range (plus constraints)
• mem_range array fixed maximum size; randomize number of valid ranges
(workaround for solve size before foreach limitation)
• Configurable constraint policy classes select number & types of ranges
map
range[0] range[1] range[2] range[3] range[N-1] range[N]
valid valid valid valid invalid invalid
size
cache
size
cache
size
cache
size
cache
... size
cache
size
cache
... ... ... ... ... ...
constraint c_count {
item.ranges.sum(r) with (int'(r.valid && (r.size == size)))
inside {[min:max]};
}
map.randomize;
Implementation
• Use policy class to inject memory map constraints into memory transaction