Write a constraint for polindrome (say 32 bit)?

In reply to surya narayana Gutha:

There can be 2 ways of doing it , one is having the logic in post_randomize function . And other one is having logic in constraint .Find below the example
Code :

rand bit[31:0] dummy; //Logic in post randomize
rand bit[31:0] dummy1; // Logic in constraint
function void post_randomize();
for(int i =0;i<16;i++)
begin
dummy[31-i] = dummy[i];
end
endfunction

constraint range {
foreach(dummy[j])
dummy1[j] == dummy1[31-j];}

Output :
1st iteration :
dummy = 10110010000101111110100001001101
dummy1 = 10110111101001111110010111101101
2nd iteration :
dummy= 11010000000111100111100000001011
dummy1 = 00111000101010011001010100011100

1 Like