[英]SystemVerilog constraint for mapping between two 2D arrays
有两个MxN 2D阵列:
rand bit [M-1:0] src [N-1:0];
rand bit [M-1:0] dst [N-1:0];
他们都将让他们都在他们1'b1的休息了P个1'b0 分别随机。
第三个名为“ map”的MxN整数数组在两个数组“ src”和“ dst”之间建立了一对一的映射。
rand int [M-1:0] map [N-1:0];
需要一个“映射”的约束条件,以便在随机化之后,对于src [i] [j]的每个元素,其中src [i] [j] == 1'b1,map [i] [j] == M * k +当dst [k] [l] == 1时为l。对于地图的每个非零元素,k和l必须是唯一的。
举一个例子:令M = 3和N = 2。
令src为
[1 0 1
0 1 0]
让dst
[0 1 1
1 0 0]
然后,“地图”的一种可能的随机化将是:
[3 0 1
0 2 0]
在上图中:
这很难表达为SystemVerilog约束,因为
由于分别对src
和dst
进行随机化,因此计算指针然后随机选择指针以填充映射可能会更容易。
module top;
parameter M=3,N=4,P=4;
bit [M-1:0] src [N];
bit [M-1:0] dst [N];
int map [N][M];
int pointers[$];
initial begin
assert( randomize(src) with {src.sum() with ($countones(item)) == P;} );
assert( randomize(dst) with {dst.sum() with ($countones(item)) == P;} );
foreach(dst[K,L]) if (dst[K][L]) pointers.push_back(K*M+L);
pointers.shuffle();
foreach(map[I,J]) map[I][J] = pointers.pop_back();
$displayb("%p\n%p",src,dst);
$display("%p",map);
end
endmodule
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.