J
Jeremy Stringer
Guest
Hello all,
I came across (to me) a bit of a tricky problem -
What I wanted to do was to write a function to take an array of
std_logic_vectors and or them together (Well, a little more than that,
but that's the part I was having trouble with). So - the inputs are
defined like this:
subtype slv_3 is std_logic_vector(2 downto 0);
subtype slv_4 is std_logic_vector(3 downto 0);
type slv_3a is array(natural range <> of slv_3;
type slv_4a is array(natural range <> of slv_4;
I then went a wrote a function looking something like this (haven't
tested this exact example):
function or_many(a: slv_3a) return std_logic_vector is
begin
return a(a'high) or or_many(a(a'high downto a'low));
end function or_many;
Now - as I wrote this, I observed that the function I was writing had
exactly the same form for both vector sizes - however, I don't know how
to (or whether it is possible to) apply the same code to each vector size.
Does anybody have anything to suggest? I might be looking at this the
wrong way, but a function seemed a nice elegant way to do this, given
the parameters of the code I was writing (same operation done multiple
places). I do understand that I am feeding different types into each
function - part of the question, I guess, is how to define the inputs in
a manner to suit the problem.
(Oh - and it has to synthesise )
Thanks,
Jeremy
I came across (to me) a bit of a tricky problem -
What I wanted to do was to write a function to take an array of
std_logic_vectors and or them together (Well, a little more than that,
but that's the part I was having trouble with). So - the inputs are
defined like this:
subtype slv_3 is std_logic_vector(2 downto 0);
subtype slv_4 is std_logic_vector(3 downto 0);
type slv_3a is array(natural range <> of slv_3;
type slv_4a is array(natural range <> of slv_4;
I then went a wrote a function looking something like this (haven't
tested this exact example):
function or_many(a: slv_3a) return std_logic_vector is
begin
return a(a'high) or or_many(a(a'high downto a'low));
end function or_many;
Now - as I wrote this, I observed that the function I was writing had
exactly the same form for both vector sizes - however, I don't know how
to (or whether it is possible to) apply the same code to each vector size.
Does anybody have anything to suggest? I might be looking at this the
wrong way, but a function seemed a nice elegant way to do this, given
the parameters of the code I was writing (same operation done multiple
places). I do understand that I am feeding different types into each
function - part of the question, I guess, is how to define the inputs in
a manner to suit the problem.
(Oh - and it has to synthesise )
Thanks,
Jeremy