shaiko
Advanced Member level 5
Hello,
My design requires converting a One Hot encoded vector to Binary from.
For this purpose - I want to write a generic function that can accept any size of vector.
My problem is that Systemverilog doesn't allow the function to have an unconstrained array input.
How can I solve this ?
This is what I wrote so far.
My design requires converting a One Hot encoded vector to Binary from.
For this purpose - I want to write a generic function that can accept any size of vector.
My problem is that Systemverilog doesn't allow the function to have an unconstrained array input.
How can I solve this ?
This is what I wrote so far.
Code:
function one_hot_to_binary ( logic /*missing_type_and_size*/ vector_one_hot ) ;
logic [ $clog2 ( $size ( vector_one_hot ) ) - 1 : 0 ] vector_binary = 0 ; // Define an appropriately sized binary vector.
foreach ( vector_one_hot [ index ] )
begin
if ( vector_one_hot [ index ] == 1'b1 ) // If the bit index is '1' do a logic OR with the index value.
begin
vector_binary = vector_binary | index ;
end
end
return vector_binary ;
endfunction