Hi Richard,
On 07/11/2013 17:46, Richard Nicholas wrote:
> Thank you both for your help. I probably did not explain what I was looking for clearly. I
> wanted a function that would just OR all the vectors in the array, not or_reduce each vector,
> creating a new vector of those results.
Reading somehow the OP it should have been indeed clear, I think the
preamble with the or_reduce example biased our mindset (or at least mine!).
> With the help of a colleague, I think we have a solution that does what I need:
>
> function array_or( vectors : req_arr) return std_ulogic_vector is
>
> variable result : std_ulogic_vector (vectors(0)'range);
>
> begin
> result := vectors(0);
> for i in 1 to req_arr'length-1 loop
> result := result or vectors(i);
> end loop;
>
> return result;
> end array_or;
Actually you get the same result simply using KJ's function preceded by
a 'transpose' function on the array (matrix):
<code>
my_array_t <= transpose (my_array);
my_vector <= or_reduce (my_array_t);
</code>
This separation will help you reuse your code, since now your functions
are not bound to your specific operation.
> It could be made slightly more general by not taking advantage of the
> fact that all the vectors are of the form (0 to N). Thanks again.
IMO that generalization has to go in the data structure, not in the
functions which operate on them. If you have an 'array' of 'something',
each element has to be the same 'something', but if you have a register
instead, you can collect vectors of different sizes.
Be aware though that depending on the operation you are doing the value
that you pick for elements that need to be padded may affect your
result. Padding with zero does not affect an or_reduce, but it does
affect an and_reduce!
Al