The opposite of what theinsideoperator does can be achieved by placing a not symbol!before it. This is applicable for both constraints and conditional statements. The following example is the same as we saw bef
constraint c_date{ month inside { [1:12] }; //约束month day inside { [1:31] }; //约束day year inside { [2010:2030] };//约束year } endclassinside是常见的约束运算符,表示变量应该属于某一个值的集合,除非述存在其他约束,否则随机变量在集合重敢值的概率是相等的。 集合里也可以使用变量。ra...
module tb6; class packet_a; rand int length; constraint cstr {soft length inside {[5:15]};} endclass class packet_b extends packet_a; //constraint cstr{ length inside {[10:20]};}//与父类同名会覆盖掉packet_a的约束 //constraint cstr1 { length inside {[10:20]};}//不同名同时满足...
constraint常见用法rand bit [7:0] data; // 随机变量 rand bit [3:0] addr; // 随机变量 rand bit [7:0] data_array[10]; // 随机数组 constraint c_data_addr { data inside {[0:100]}; // data的取值范围是0到100 addr dist {0
// Use of multiple operators in a single expression is not allowed constraint my_error { 0 < min < typ < max < 128; } // This will set min to 16 and randomize all others constraint my_min { min == 16; } // This will set max to a random value greater than or equal to 64...
classABC;randbit[3:0]mode;randbitmod_en;constraintc_mode{// If 5 <= mode <= 11, then constrain mod_en to 1// This part only has 1 statement and hence do not// require curly braces {}if(modeinside{[4'h5:4'hB]})mod_en==1;// If the above condition is false, then do the...
2 inside { some_dynamic_array }; } 相反,如果我们约束数组中不包含值2呢? constraintnot_contains_c {!(2 inside { some_dynamic_array });} 3、约束数组中每个值都是唯一的。 constraintall_elems_unique_c {unique{some_dynamic_array}; }
The constraint is disabled by using the constraint_mode method, so on randomization constraint solver will not consider the constraint. class packet; rand bit [3:0] addr; constraint addr_range { addr inside {5,10,15}; } endclass module static_constr; initial begin packet pkt; pkt = new(...
)inside{[1:8]};}endclass//使用foreach产生递增的数组元素的值classAscend;randunitd[10];constraint...
Using soft constraint In the example below, a previous example problem is solved using soft constraints, Constraint declared inside the class will get suppressed by inline constraints. class packet; rand bit [3:0] addr; constraint addr_range { soft addr > 6; } endclass module soft_constr; ...