This question is related with How to create random dynamic 2D arrays in SystemVerilog? | Verification Academy
How do I put the constraint value into the 2D array in constraint by separately ?
class A;
rand logic [3:0] width;
rand logic [3:0] height;
rand logic [3:0] DA[][];
//rand logic [3:0] [] DA2 [][];
//rand logic [3:0] [][] DA3[][];
constraint con_A{
width inside {[1:5]};
height inside {[6:9]};
DA.size == width;
foreach(DA[i]) {
DA[i].size == height;
DA[i] inside{[1:5]};
/*
foreach(DA[i][j]) {
DA[i][j] inside {[6:15]};
}
*/
foreach(DA[i,j]) {
DA[i][j] inside {[6:15]};
}
}
}
endclass
module test;
A a=new();
initial begin
if(!a.randomize())
$error("Error_Randomize");
$display( "a.width:%0d, a.height:%0d", a.width, a.height);
foreach(a.DA[i,j])
$display("i:%0d, j:%0d, a.DA:%0d", i ,j, a.DA[i][j]);
end
endmodule
As you can see the code. I put the constraint value into the 2D array by using “$urandom_range()” by separately.
Q1. DA[i] inside{[1:5]}; is faced error with
- Error: testbench.sv(16): (vlog-2728) Inside operator requires a singular type.
– Compiling module test
** Error: testbench.sv(16): (vlog-2728) Inside operator requires a singular type.
How do I put the constraint value into the 2D array in constraint by separately ?
Q2. What is the difference between
foreach(DA[i][j]) {
DA[i][j] inside {[6:15]};
}
and
foreach(DA[i,j]) {
DA[i][j] inside {[6:15]};
}
?