Hi ,
Can some one help in writing a constrain for [7:0]byte_array[32] . The constraint is each byte in next consecutive location should not change by more then 4 bits. I am not able to write this cleanly without using for loop. Any suggestions.
In reply to manav33:
The clean way of writing this IS using a
foreach loop. Why is that a problem for you?
In reply to dave_59:
In reply to manav33:
The clean way of writing this IS using a
foreach loop. Why is that a problem for you?
I tried using this . It looks correct ? I am doing ex or to count how many bits have changed and making sure its less then or equal to 4 .
rand [7:0]byte_array[32]
bit [7:0] value_exor ;
int count;
int i = byte_array.size();
constraint c_byte_array {
foreach(i) begin
value_exor=byte_array[i]^byte_array[i+1];
foreach(value_error[j]) begin
if(value_error[j]==1)
count++;
end
count<=4;
end
}
In reply to manav33:
That’s not how foreach works in a constraint.
constraint c_byte_array {
foreach(byte_array[ii]) if (ii!=0) // guard against out of bounds indexing
($countones(byte_array[ii]) - $countones(byte_array[ii-1])) inside {[-4:4]}
}
In reply to dave_59:
In reply to manav33:
That’s not how foreach works in a constraint.
constraint c_byte_array {
foreach(byte_array[ii]) if (ii!=0) // guard against out of bounds indexing
($countones(byte_array[ii]) - $countones(byte_array[ii-1])) inside {[-4:4]}
}
Hi Dave
Thanks for your reply. If i understand correctly your code is making sure that between two consecutive memory locations the difference in number of “1”'s is not more then 4 correct ?
However i want the constraint such that between two locations no more then 4bits have toggled ( thats why i used Xor first to check how many bits have changed ), Can you please update constraint based on required scenario ? Thanks
In reply to manav33:
It was a quick guess for me. Show me an example where my constraint does not meet your requirements.