约束控制
//constraint_mode()
constraint c {length inside {[1:32]};}
p.c.constraint.mode(0);//0关闭,1打开,默认打开
//rand_mode
p.length.rand_mode(0);//随机进行关闭
p.length=42;
//randomiza()with{}
assert(c.randmize()with{data<10;});//增加约束
randomize(变量名)//单独控制变量随机
调用randomize会同时调用pre_randomize,randomize和post_randomize
pre_randomize(准备):设定与randomize相关的各个变量的值
post_randomize(收尾):调用相关的函数对randomize出来的变量进行后续处理
randomize调用失败,post_randomize将不会执行,但pre_randomize必执行
function不消耗仿真时间,task消耗仿真时间
约束的重载
1.constraint_mode(0)关闭约束,再用randomize()with{}重新约束
2.子类extends父类,再定义同名约束覆盖父类约束
解的概率
······························································································
执行多次是一样的,伪随机
解决方法:随机化种子
每一次结果都不同,缺点:不知道种子号
·················································································································
x约束y,y约束x的概率
优先级:randc>rand
class impact1;
randc bit x; // 0或1
rand bit [1:0] y; //0,1,2或3
constraint c_xy{
(x==0)-> y==0;
}
endclass
class impact1;
rand bit x; // 0或1
randc bit [1:0] y; //0,1,2或3
constraint c_xy{
(x==0)-> y==0;
}
endclass
solve...before约束引导概率分步
solve x before y;//先拿x,再拿y
不要过度使用,否则会降低计算速度,使约束难以理解