I am a systemverilog user and I have faced a strange (from my point of view) behavior of combination of unique method called for fixed array with "with" clause.
module tb;
int array[9] = '{4, 7, 2, 5, 7, 1, 6, 3, 1};
int res[$];
initial begin
res = array.unique(x) with (x <= 3);
$display ("unique : %p", res);
end
endmodule
I've expected to get queue {2,1,3} but instead I have got {4,2}.
I can't understand Why there is a one at the index 0? and Why are 2 and 3 missing from the result?
Let me explain the result you were getting.
The with
clause of the unique
method defines the expression used to determine uniqueness . It will delete all but one arbitrary element from the set of elements having matching expressions.
Since you chose an expression having a result of 1'b0 or 1'b1, it chose one out of the four elements (2, 1, 3, 1) where x <= 3
was true (2), and one out of the five elements (4, 7, 5, 7, 6) where it was false (4).
You are trying to combine the find
method with the unique
method in a single operation. It doesn't work that way. You have to do it in two separate operations:
module tb;
int array[9] = '{4, 7, 2, 5, 7, 1, 6, 3, 1};
int res[$];
initial begin
res = array.find(x) with (x <= 3);
res = res.unique;
$display ("unique : %p", res);
end
endmodule
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.