In reply to harsh pandya:
In reply to Manikanta Kopparapu:
Hi Harsh,
Thanks for the response. But still i have some queries which I have commented
Please, use code tag. It will provide easy visibility over code.
Btw, Your constraints are conflict due to below 2 condition contradicting each other.
// this constraints assign array_1[0] = 0, array_1[1] = 1 ... array_1[4] = 4;
constraint addr_unique_values{
foreach(array_1[i]) array_1[i]==i;
}
// in this line you are doing
// array_1[0] = array_1[4] ==> array_1[0] = 4 which is contradicting with array_1[0] = 0;
// So, your constraints is conficting.
<font size=20> **//May I know why the conflict occurs I am not facing any issues
//while assigning array_1[1] =array_1[3]
//array_1[2]= array_1[2]
//array_1[3] =array_1[1]
// But constraint solver issue is only when assigning the
//first and last locations of the array
//array_1[0]= array_1[4]
//array_1[4]=array_1[0]</font>**
uaeg_1.randomize() with {
foreach(array_1[i]) array_1[i] == array_1[(array_1.size()-1) - i];
};
And also in order to reverse array you not need to randomize again.
Simple streaming operator is enough to archive this. ( See below code )
class unique_array_example;
rand bit [7:0] array_1[];
constraint addr_size{
array_1.size() == 5;
}
constraint addr_unique_values{
foreach(array_1[i]) array_1[i] == i;
}
endclass : unique_array_example
module abc();
unique_array_example uaeg_1;
initial begin
uaeg_1 = new();
//This loop is for the unique array values
// Note : - I dont know why you use repeat 1. It has not meaning.
repeat(1) begin
uaeg_1.randomize();
foreach(uaeg_1.array_1[i]) begin
$display("the value of a is %d and the value of is %d ",uaeg_1.array_1[i],i);
end
end
$display("Before:- \n%p",uaeg_1.array_1);
uaeg_1.array_1 = {<<8{uaeg_1.array_1}};
<font size=20>//Can you tell me the significance of the <<8 which is nothing left shifted ?</font>****
$display("After:- \n%p",uaeg_1.array_1);
//uaeg_1.randomize() with{ foreach(array_1[i])
// array_1[i] == array_1[ (array_1.size()-1) - i];
//};
foreach(uaeg_1.array_1[i]) begin
$display("the value of in reverse array a is %d and the value of is %d ",uaeg_1.array_1[i],i);
end
end
endmodule
Thanks!