在 VHDL 进程中的 for 循环中访问一个变量

Accessing one variable in a for loop within a VHDL process

我想在 for 循环中递增一个变量,它指示我条件语句在向量中多久为真一次。知道VHDL中的for循环会创建n个并行实例,难不成这"access"一个变量?考虑到以下在模拟中运行良好的场景,我怀疑它在现实中是否也能运行。有人能解释一下它在现实中是如何工作的吗?

variable_p : process(clk)
 variable var : integer;
begin
  if rising_edge(clk) then
    var := 0;
    for i in 0 to 7 loop
      if some_vector(i) = '1' then
        var := var + 1;
        other_vector(var) <= '1';
      end if;
    end loop;
  end if;

更新

我综合了以下设计:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;

entity var_p is
  Port (
    clk : in std_logic;
    some_vector : in std_logic_vector( 7 downto 0 );
    other_vector : out std_logic_vector( 7 downto 0 )
  );
end var_p;

architecture Behavioral of var_p is
begin
  var_p : process( clk )
    variable var : integer range 0 to 7;
  begin
    if rising_edge( clk ) then
      var := 0;
      for i in some_vector'range loop
        if some_vector(i) = '1' then
          var := var + 1;
          other_vector(var) <= '1';
        end if;
      end loop;
    end if;
  end process;
end Behavioral;

这会为每个 other_vector 元素生成一个 LUT,该元素将几个 some_vector 元素作为输入 [ 1].由此我可以得出结论,对于 some_vector 中的每个“1”,var 确实得到了 'incremented'。我现在也更好地理解变量只是用于确定 LUT 配置的辅助构造,而不是合成的任何东西。但是如果我在这里错了请纠正我,因为我仍然不是百分百确定。如果我手上有一块板,我会尝试在现实中验证我的观察。

[1] https://imgur.com/a/pBL0Diy

当我终于找到我的 Basys3 板时,我可以尝试设计了。事实上,综合和实施的设计符合预期:

other_vector中的“1”与some_vector中“1”的个数完全相同.

在我的测试中,我将输入向量连接到开关,将输出向量连接到 LED(见下文)。

这证实了在 for 循环的每个 'iteration' 中,对于每个为“1”的元素,var 都会递增。

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;

entity var_p is
  Port (
    CLK100MHZ : in std_logic;
    sw : in std_logic_vector( 15 downto 0 );
    LED : out std_logic_vector( 15 downto 0 )
  );
end var_p;

architecture Behavioral of var_p is
begin
  var_p : process( CLK100MHZ )
    variable var : integer range 0 to 15;
  begin
    if rising_edge( CLK100MHZ ) then
      var := 0;
      LED <= ( others => '0' );
      for i in SW'range loop
        if sw( i ) = '1' then
          var := var + 1;
          LED( var ) <= '1';
        end if;
      end loop;
    end if;
  end process;
end Behavioral;