R
Richard Nicholas
Guest
Hi all,
I posted back in November that I needed a funtion that would take as input an array of
std_ulogic_vectors and return a std_ulogic_vector which is the OR of all of the vectors in
the array. What we came up with is:
function array_or( vectors : arr) return std_ulogic_vector is
variable result : std_ulogic_vector (vectors(0)'range);
begin
result := vectors(0);
for i in 1 to arr'length-1 loop
result := result or vectors(i);
end loop;
return result;
end array_or;
where arr is defined like:
type arr is array (0 to 99) of std_ulogic_vector(0 to 15);
So array_or works for all arrays defined as type arr but not, for example, arrays of these
types:
type arr1 is array (0 to 99) of std_ulogic_vector(0 to 3);
type arr2 is array (0 to 99) of std_ulogic_vector(0 to 63);
type arr3 is array (0 to 99) of std_ulogic_vector(0 to 31);
type arr4 is array (0 to 99) of std_ulogic_vector(0 to 87);
I'm having trouble making the function general though because I will have numerous array
types that I want to use with this one function. In my case all the arrays will all have the
same number of array elements but the std_ulogic_vectors contained in the arrays have
different lengths like the examples above.
I want to be able to run array_or on diferent array types without having a function (even
overloaded) for all the different sizes of std_ulogic_vector.
Can this be done? The funtion above is already figuring out the range of the vector but I
can't figure out how to pass some kind of generic sized array to the function. Any help
would be appreciated.
Richard Nicholas
I posted back in November that I needed a funtion that would take as input an array of
std_ulogic_vectors and return a std_ulogic_vector which is the OR of all of the vectors in
the array. What we came up with is:
function array_or( vectors : arr) return std_ulogic_vector is
variable result : std_ulogic_vector (vectors(0)'range);
begin
result := vectors(0);
for i in 1 to arr'length-1 loop
result := result or vectors(i);
end loop;
return result;
end array_or;
where arr is defined like:
type arr is array (0 to 99) of std_ulogic_vector(0 to 15);
So array_or works for all arrays defined as type arr but not, for example, arrays of these
types:
type arr1 is array (0 to 99) of std_ulogic_vector(0 to 3);
type arr2 is array (0 to 99) of std_ulogic_vector(0 to 63);
type arr3 is array (0 to 99) of std_ulogic_vector(0 to 31);
type arr4 is array (0 to 99) of std_ulogic_vector(0 to 87);
I'm having trouble making the function general though because I will have numerous array
types that I want to use with this one function. In my case all the arrays will all have the
same number of array elements but the std_ulogic_vectors contained in the arrays have
different lengths like the examples above.
I want to be able to run array_or on diferent array types without having a function (even
overloaded) for all the different sizes of std_ulogic_vector.
Can this be done? The funtion above is already figuring out the range of the vector but I
can't figure out how to pass some kind of generic sized array to the function. Any help
would be appreciated.
Richard Nicholas