随机1点的数量在UVM阵列时不使用$ countones?

问题描述 投票:0回答:1

在UVM,我想约束的阵列,这样我可以修复数组3者的数量,我已经写了利用使用$ countones,但如何做到这一点,而不使用$ countones约束下面的代码?

class class_1;
rand bit[31:0] array;

constraint three_ones {
$countones(array) == 3;
}
endclass
random constraints system-verilog uvm
1个回答
0
投票

你所写的是相当于

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,但太辛苦了我。

© www.soinside.com 2019 - 2024. All rights reserved.