I have a w*y-bit width std_logic_vector
named matrix
where w and y are integers. I want to have y-bit width std_logic_vector
called output
that its bits are concurrently assigned to AND of w bits of matrix
elements.
For example, w=5 y=3:
output(2) <= matrix(14) and matrix(13) and matrix(12) and matrix(11) and matrix(10);
output(1) <= matrix(9) and matrix(8) and matrix(7) and matrix(6) and matrix(5);
output(0) <= matrix(4) and matrix(3) and matrix(2) and matrix(1) and matrix(0);
In the example, you can see that output
is y-bit long which is 3, and each bit of the output
is assigned to AND of w-bits of matrix
which is 5.
Now, I want to write it with generics. I have tried to write it in two for..generate
loop but I cannot handle it. What should be in the right hand side of the output(i)
? It can also be implemented in another way, and I am very welcome to another ideas. It does not have to be in the way I thought.
library ieee;
use ieee.std_logic_1164.all;
entity module is
generic (
w : integer := 5; -- input width
y : integer := 3 -- output width
);
port (
matrix : in std_logic_vector(w * y - 1 downto 0); -- matrix
output : out std_logic_vector(y - 1 downto 0) -- output
);
end entity module;
architecture rtl of module is
begin -- architecture rtl
AND_FOR: for i in y - 1 downto 0 generate
AND_FOR2: for j in w - 1 downto 0 generate
output(i) <= ????;
end generate AND_FOR2;
end generate AND_FOR;
end architecture rtl;