So I was trying to make sure that for any repeated index bits i.e cache_addr[14:9] the tag bits of cache address (cache_addr[31:15]) must be different. For every index i, I saved the tag bits in flag[i] vector. But inside the constraint I can not use the flag[i].elements. How do I do that?
Here’s how my class looks like:
class Random;
rand bit [31:0] cache_addr;
bit [16:0] flag[$][$]; // push tag_bits for each Index
int size_i = 0, q_index = 0;
int tag,index,temp_index;
bit [16:0] index_arr[1000]; // Flag for index, visited or not
bit [7:0] index_arr_ref[1000]; // The index of the flag queue for each Individual Index
//constraint c1 {cache_addr[14:9] == 13; }
//constraint c2 {cache_addr[31:15] inside {[0:20]} ; }
constraint c4 {if (index_arr[cache_addr[14:9]] == 1) !(cache_addr[31:15] inside{ flag[index_arr_ref[cache_addr[14:9]]] }) ;}
function void post_randomize();
index = cache_addr[14:9];
tag = cache_addr[31:15];
if(flag.size()== 0) begin
flag[q_index].push_back(tag);
index_arr[index] = 1;
index_arr_ref[index] = q_index++;
end
else begin
if(index_arr[index] == 0) begin // if the index is new
index_arr[index] = 1; // visiting the index
flag[q_index].push_back(tag); // inserting the tag in the default flag[i]
index_arr_ref[index] = q_index++; // saving the index no of queue for each index
end
else begin // if the index was selected before
temp_index = index_arr_ref[index]; // getting the index of queue
flag[temp_index].push_back(tag); // inserting the new tag in that index
end
end
endfunction : post_randomize
endclass : Random