class child;
rand bit[3:0] dy_array[][]; //2-D dynamic array
constraint arr_size_limit{dy_array.size inside{[1:4]}; foreach(dy_array[i]) (dy_array[i].size==2); } //constraint to limit the dy_array size
endclass:child
I want to constraint the 2-D dynamic array.
above constraint limit the 1st dimension size but it is showing the error for the 2nd dimension.
please suggest if there any way to do it.
thanks & regards
In reply to jj_bukhari:
Please use code tags making your code easier to read. I have added them for you.
I’m not getting any errors from running your code. It would help to show a minimal complete example and the error you are getting.
This is what I tred
class child;
rand bit[3:0] dy_array[][]; //2-D dynamic array
constraint arr_size_limit{dy_array.size inside{[1:4]}; foreach(dy_array[i]) (dy_array[i].size==2); } //constraint to limit the dy_array size
endclass:child
module top;
child c = new;
initial repeat (5) begin
assert(c.randomize);
$displayh("%p", c.dy_array);
end
endmodule
and the results I got
# '{'{a, 6}, '{5, e}, '{7, 7}}
# '{'{e, 4}, '{3, f}, '{d, 4}, '{3, b}}
# '{'{f, a}}
# '{'{5, 0}}
# '{'{1, 5}, '{5, 1}, '{6, f}, '{4, 0}}
In reply to dave_59:
Thanks dave for reply
I was not aware of how to use code tags, now I got it how to use, I will take care of it.
class child;
rand bit[3:0] dy_array[][];
rand bit[3:0]addr;
rand bit[7:0]data;
function void post_randomize();
$display($time,"\t","addr=%0d\tdata=%0d\t dy_array=%p",addr,data,dy_array);
endfunction:post_randomize
constraint arr_size_limit{dy_array.size inside{[1:4]}; foreach(dy_array[i]) (dy_array[i].size==2); }
endclass:child
module randomize_prac;
child ch=new();
initial
begin
repeat(30)
begin
void'(ch.randomize());
end
$finish;
end
endmodule
Actually, I was using Cadence Tool, and it gives this error.
Observed simulation time : 0 FS + 0
xmsim: *W,RNDOCS: These constraints contribute to the set of conflicting constraints:
constraint arr_size_limit{dy_array.size inside{[1:4]}; foreach(dy_array[i]) (dy_array[i].size==2); } (./testbench.sv,17)
void'(ch.randomize());
|
xmsim: *W,SVRNDF (./testbench.sv,30|27): The randomize method call failed. The unique id of the failed randomize call is 1.
I tried that code on Quartus Tool and it worked fine.
thank you