无法比较"迭代器"我用std_logic_vector里面生成

时间:2014-04-07 15:27:02

标签: vhdl

for generate 构造中,我尝试在比较中使用 i ,但我遇到了麻烦。

代码是:

mult_lineA_colX :
for i in 0 to DIM-1 generate
begin
    if i /= to_integer(unsigned(iterNb)) then
        multVect(i) <= A_line(i) * X_mat(i);
    else
        multVect(i) <= (others => '0');
    end if;
end generate;

上下文:

type A_line_type is array (0 to DIM-1) of std_logic_vector(DATA_SIZE-1 downto 0);
signal A_line : A_line_type := (others=>(others=>'0'));

type X_type is array (0 to DIM-1) of std_logic_vector(DATA_SIZE-1 downto 0); 
signal X_mat : X_type := (others=>(others=>'0'));

type multVect is array (0 to DIM-1) of std_logic_vector (DATA_SIZE*2-1 downto 0);

库:

use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_SIGNED.ALL;
use IEEE.NUMERIC_STD.ALL;

我在条件行上出错:

ERROR:HDLCompiler:806 - "/path/to/file.vhd" Line 213: Syntax error near "if".

是否允许使用 i ?我该如何解决这个问题或将其改为具有相同效果的东西?

我也尝试使用 when 构造函数来获得相同的效果,但我得到了这两个错误:

ERROR:HDLCompiler:56 - "/path/to/file.vhd" Line 211: <i> is not a signal.
ERROR:HDLCompiler:258 - "/path/to/file.vhd" Line 211: Cannot convert type integer to type multvect

1 个答案:

答案 0 :(得分:1)

VHDL '93不支持进程外的if-then-else结构。您可以为生成语句做的下一个最好的事情是这样的:

library ieee;
use ieee.std_logic_1164.all;
entity foo is
end entity foo;
architecture bar of foo is

begin  -- architecture bar

  multV: for i in 0 to DIM-1 generate
    constant compare : boolean := (i /= to_integer(unsigned(iterNb)));
  begin
    case_1: if compare generate
      multVect(i) <= A_line(i) * X_mat(i);
    end generate case_1;
    case_2: if not compare generate
      multVect(i) <= (others => '0');
    end generate case_2; 
  end generate multV;
end architecture bar;