VHDL 从数组中选择列

VHDL Column selection from array

type matrixsignal is array (LEVELS downto 0) of std_logic_vector(NBIT-1 downto 0);
signal p_matrix, g_matrix: matrixsignal;
signal col_temp_g, col_temp_p : std_logic_vector(LEVELS downto 0);

...

col_temp_p<=p_matrix(LEVELS downto 0)(j-1);
col_temp_g<=g_matrix(LEVELS downto 0)(j-1);

大家好! 我想 select 并复制 2 个数组的整个列 (j-1)...但是编译器告诉我这种方式不正确。 怎么可能呢?

P.S。 LEVELS,NBIT,j是初始化的参数。。。我没有报他们的初始化。

您应该将 matrixsignal 定义为二维数组,而不是嵌套另一个一维数组的 one-dimensional 数组。

type matrixsignal is array(LEVELS downto 0, NBIT - 1 downto 0) of std_logic;

PoC-Library offers that type as T_SLM (std_logic_matrix) together lot's of manipulation functions and procedures in package PoC.vectors. E.g. PoC defines a get_col函数是这样的:

function get_col(slm : T_SLM; ColIndex : natural) return std_logic_vector is
  variable slv      : std_logic_vector(slm'range(1));
begin
  for i in slm'range(1) loop
    slv(i)  := slm(i, ColIndex);
  end loop;
  return slv;
end function;

用法:

subtype matrixsignal is T_SLM(LEVELS downto 0, NBIT - 1 downto 0);
signal p_matrix, g_matrix     : matrixsignal;
signal col_temp_g, col_temp_p : std_logic_vector(LEVELS downto 0);

...

col_temp_p <= get_col(p_matrix, j - 1);
col_temp_g <= get_col(g_matrix, j - 1);

包PoC.vectors可以合成

提供更多功能,如:

  • 对整行进行切片
  • 切片子矩阵
  • 扁平化/序列化
  • 从向量/反序列化创建矩阵
  • 重载布尔运算符
  • 行/列赋值
  • 矩阵合并
  • 转换to/from一维数组类型包含另一个一维数组类型
  • ...