I have two queues of sequence items, one from the dut and one from the ref. I’d like to count the amount of transactions that match so I thought about using the sum
reduction method:
my_seq_item ref_queue[$];
my_seq_item dut_queue[$];
// find_matches() relies on caller to make sure the queues are not empty
function int find_matches();
return dut_queue.sum() with (item.compare(ref_queue[item.index]);
endfunction
but apparently it doesn’t behave like I would expect.
The 1800-2017 states (7.12.4):
The following reduction methods are supported:
— sum() returns the sum of all the array elements or, if a with clause is specified, returns the sum of the values yielded by evaluating the expression for each array element.
I assume the the ‘sum of the values yielded’ would be the sum of 1'b1
and 1'b0
reported by the compare operation.
Should I cast the result into a bit datatype for the sum to work? Like this:
function int find_matches();
return dut_queue.sum() with (item.compare(bit'(ref_queue[item.index]));
endfunction
I’m trying the above and will report, but if in the meantime someone is able to catch another issue that would be great.