I want to compare two slices of two different arrays to determine if they are equal or not. The following code is what I’m trying to use “array reduction” together with “iterator index querying”:
module array_slice_comparison;
bit [31:0] array1[100];
bit [31:0] array2[100];
int index_to_compare = 3;
initial begin
std::randomize(array1)with{array1[3] == 32'h01234567;};
std::randomize(array2)with{array2[3] == 32'h01234567;};
if (array1.and() with (item.index == index_to_compare || item == array2[item.index]))
$display("array1 == array2");
else
$display("array1 != array2");
$display("array1[%0d] = %h", index_to_compare, array1[index_to_compare]);
$display("array2[%0d] = %h", index_to_compare, array2[index_to_compare]);
end
endmodule : array_slice_comparison
What am I missing here?
Also, how would I be able to extend the above to multiple consecutive indexes? Say between 3 and 5?
Thanks for your feedback.
The above code can be run on EDA Playground