ASIC Verification: Randomization 2
ASIC Verification: Randomization 2
Randomization 2
Topics
Controlling Constrains
Controlling Random Variables
Array Constraints
Scenario Generation
Random Device Configuration
Controlling Constraints
In-line Constraints
class Transaction;
rand bit [31:0] addr, data;
constraint c1{addr inside {[0:100],[1000:2000]};}
endclass
in-line constraint
Transaction t;
initial begin
t=new();
assert(t.randomize() with {addr>=50; addr<=1500; data<10;});
driveBus(t);
assert(t.randomize() with {addr==2000; data>10;});
driveBus(t);
end
Controlling Constraints
class Bounds;
rand int size;
int max_size=100;
constraint c_size{size inside {[1:max_size]};}
endclass
Controlling Constraints
Value
Meaning
Description
OFF
ON
Controlling Constraints
Controlling Constraints
Using constraint_mode
Controlling Constraints
end
Meaning
Description
OFF
Sets the specified variable to inactive so that they are not randomized on
subsequent calls to randomize() method
ON
class Packet;
rand integer src, dst;
endclass
int r;
Packet packet_a=new();
packet_a.rand_mode(0);
packet_a.src.rand_mode(1);
r=packet_a.dst.rand_mode();
class Packet;
rand bit[7:0] length, payload[];
constraint c_valid{legth >0 ; payload.size()==length;}
endclass
intial begin
Packet p;
p.lenght.rand_mode(0);
p.length=42;
assert(p.randomize());
end
Array Size
class dyn_size;
rand logic [31:0] d[];
constraint d_size {d.size() inside {[1:10]};}
endclass
Example
Example
parameter MAX_TRANSFER_LEN=10;
class StrobePat;
rand bit strobe[MAX_TRANSFER_LEN];
constraint c_set_four {strobe.sum()==4h4;}
endclass
intial begin
StrobePat sp;
int count=0;
sp=new();
assert(sp.randomize());
foreach (sp.strobe[i]) begin
@bus.cb
bus.cb.strobe<=sp.strobe[i];
if(sp.strobe[i])
bus.cb.data<=data[count++];
end
end
class good_sum;
rand unint len[];
constraint c_len {foreach (len[i])
len[i] inside {[1:255]};
len.sum<1024;
len.size() inside {[1:8]};}
endclass
Scenario Generation
Can make a single bus transaction, a single network packet or a single processor
instruction
DMA transfers
Cache fills
Network traffic due to browsing internet, reading e-mails etc.
Deep pipelines for processors
Scenario Generation
Second chooses
between pop or push
randsequence( main )
main: first second done ;
first: add | dec ;
second: pop | push ;
done: { $display("done"); };
add: { $display("add"); };
dec: { $display("dec"); };
pop: { $display("pop"); };
push: { $display("push"); };
endsequence
Example of randsequence
add
add
dec
dec
pop done
push done
pop done
push done
Possible Outcomes
Scenario Generation
initial begin
for(int i=0; i<15; i++) begin
randsequence (stream)
stream : cfg_read:=1|
io_read:=2|
mem_read:=5;
cfg_read: {cfg_read_task;}|
{cfg_read_task;} cfg_read;
mem_read: {mem_read_task;}|
{mem_read_task;} mem_read;
io_read: {io_read_task;}|
{io_read_task;} io_read;
endsequence
end
end
task run();
foreach(gen[i])
if(cfg.in_use[i] begin
gen[i].run();
.
end
endtask
task wrap_up();
endtask
endclass
Thank You