1. 产生随机数
(1)系统函数$urandom()或者std::urandom();
(2)系统函数$urandom_range(a,b)或者std::urandom_range(a,b);
(3)randcase,随时可使用。
randcase
1 : rand_data = $urandom_range(0,10);
2 : rand_data = $urandom_range(20,30);
3 : rand_data = $urandom_range(30,40);
1 : rand_data = $urandom_range(40,50);
1 : rand_data = $urandom_range(50,60);
endcase
2. constraint
在class内部定义、编写。
constrain para_cons{
cfg_cons0==128;
cfg_cons1 inside {1,3,5,7};
cfg_cons2 inside {[10:20],[30:40],50,60,70};
((cfg_cons3==1) && (cfg_cons4==0)) -> (cfg_cons5==2);
cfg_cons6<=cfg_cons7;
cfg_cons8%2==0;
((cfg_cons9>=24) && (cfg_cons9<=72)) -> (cfg_cons10==0);
((cfg_cons9>=73) && (cfg_cons9<=144)) -> (cfg_cons10==1);
foreach(cfg_cons11[i]){
cfg_cons11[i] inside {[0:200]};
cfg_cons11[i]%3==1;
cfg_cons11[i]<=cfg_cons12[i];
}
foreach(cfg_cons13[i][j]){
cfg_cons13[i][j] inside {[0:200]};
cfg_cons13[i][j]%2==0;
cfg_cons13[i][j]>=cfg_cons14[i][j];
}
(cfg_cons15 + cfg_cons16) inside {[0:500]};
(cfg_cons17=0) -> (cfg_cons18!=1);
cfg_cons19 dist{
[16'h0000:16'h0fff] := 1,
[16'h1000:16'h2fff] := 0,
[16'h3000:16'h3fff] :/ 10,
[16'h4000:16'hfffe] := 1,
16'hffff := 1
}
}