在UVM,我想约束的阵列,这样我可以修复数组3者的数量,我已经写了利用使用$ countones,但如何做到这一点,而不使用$ countones约束下面的代码?
class class_1;
rand bit[31:0] array;
constraint three_ones {
$countones(array) == 3;
}
endclass
你所写的是相当于
constraint three_ones {
int'(array[0]) + int'(array[1]) + int'(array[2]) + ... + int'(array[31]) )
== 3;
}
endclass
若要以编程方式做到这一点,没有任何功能,您可以创建索引列表应该设置为彼此阵列。数组的大小是你想设置一个数。
bit [0:255] array;
int countones = 5;
rand int unsigned bitset[];
constraint c_bits { bitset.size == countones;
foreach(bitset[i]) bitset[i] inside {[0;$bits(array)-1];
unique {bitset};
}
function void post_randomize();
array = 0;
foreach(bitset[i]) array[bitset[i]] = 1'b1;
endfunction
现在有一种方法可以做到这一点没有唯一约束,没有post_randomize,但太辛苦了我。