alexgk
alexgk

Reputation: 13

Slice from a matrix to a vector in VHDL2008

I have a two dimensional matrix of type 'std_logic_vector' of which I need to slice one column or line to extract an (one dimensional) array of type 'std_logic_vector'. I have this problem using the VHDL2008 standard. I am aware that nested arrays would solve my issue, though I am curious if a solution using matrices exists.

Trying to give to the matrix only one index does not give me an array, but results in an error that the type can not be resolved.

Definition of the matrix:

library IEEE;
    use IEEE.STD_LOGIC_1164.all;

package package1 is
    type MATRIX_TYPE is array (natural range <>, natural range <>) of std_logic_vector;

    type VECTOR_TYPE is array (natural range <>) of std_logic_vector;
end package1;

Entity of subcomponent:

library IEEE;
   use IEEE.STD_LOGIC_1164.all;
library WORK;
   use WORK.PACKAGE1.ALL;

entity subcomponent is
   port (
       input_vector : in  VECTOR_TYPE;
   );
end subcomponent;

architecture arch of subcomponent is
begin
end architecture;

Top component where problem occurs:

library IEEE;
   use IEEE.STD_LOGIC_1164.all;
library WORK;
   use WORK.PACKAGE1.ALL;

entity component1 is
end entity;

architecture arch of component1 is

   constant subcomponents : integer := 10;
   signal matrix : MATRIX_TYPE (0 to subcomponents - 1, 0 to 15) (31 downto 0);

begin

   SUBCOMPONENT_ARRAY : for i in 0 to subcomponents - 1 generate
       subcomponent_i : entity work.subcomponent(arch)
       port map (
           input_vector => matrix(i) --matrix(i) does not work!
       );
   end generate;

end architecture;

Upvotes: 1

Views: 466

Answers (2)

Tricky
Tricky

Reputation: 4471

Unfortunately, you cannot slice a 2+ D array in VHDL. So you either have to stick with nested 1D arrays for easy slicing, or create a slicing function to do what you want.

function slice_row(m : MATRIX_TYPE; row : integer) return VECTOR_TYPE is
  variable r : VECTOR_TYPE(m'range(2))(m'element'range);
begin
  for i in r'range loop
    r(i) := m(row, i);
  end loop;

  return r;
end function;

Upvotes: 1

Giampietro Seu
Giampietro Seu

Reputation: 816

I think something like this could work:

SUBCOMPONENT_ARRAY : for i in 0 to subcomponents - 1 generate
   block_label : block
      signal temp_vector : VECTOR_TYPE(0 to 15) (31 downto 0);
   begin
      SUBVECTOR_ARRAY : for j in 0 to 15 generate
         temp_vector(j) <=  matrix(i,j);
      end generate;

      subcomponent_i : entity work.subcomponent(arch)
         port map (
            input_vector => temp_vector
         );
   end block block_label;
end generate;

You extract the matrix elements one by one and assign them to a temporal vector, then pass the temporal vector to the subcomponent.

Upvotes: 1

Related Questions