寄存器的VHDL综合 - 每个寄存器与一个合并过程的独立过程

时间:2013-04-27 15:03:46

标签: vhdl

假设我有两个名为 reg_operand1 reg_operand2 的寄存器。对于它们两者,我有一个适当的写使能信号。我读到的某个地方我应该为每个寄存器赋值分别进行处理,如下所示:

process(CLK, RESET)
begin
    if (RESET = '1') then
        reg_operand1 <= (others => '0');
    elsif (CLK'event and CLK = '1') then
        if reg_operand1_we='1' then 
            reg_operand1 <= DI;
        end if;
    end if;
end process;

process(CLK, RESET)
begin
    if (RESET = '1') then
        reg_operand2 <= (others => '0');
    elsif (CLK'event and CLK = '1') then
        if reg_operand2_we='1' then 
            reg_operand2 <= DI;
        end if;
    end if;
end process;

但是,如果我将流程合并到此会发生什么?合成电路会不同吗?另外,如果我在合并过程中的if语句之间添加“elsif”怎么办?合成器会将多路复用器插入电路吗?谢谢!

process(CLK, RESET)
begin
    if (RESET = '1') then

        reg_operand1 <= (others => '0');
        reg_operand2 <= (others => '0');

    elsif (CLK'event and CLK = '1') then

        if reg_operand1_we='1' then 
            reg_operand1 <= DI;
        end if;

        if reg_operand2_we='1' then 
            reg_operand2 <= DI;
        end if;

    end if;
end process;

2 个答案:

答案 0 :(得分:2)

第二个将生成与第一个完全相同的硬件,并且如前所述,包含较少的样板。

如果我理解你关于elsif的问题,你建议:

process(CLK, RESET)
begin
    if (RESET = '1') then

        reg_operand1 <= (others => '0');
        reg_operand2 <= (others => '0');

    elsif (CLK'event and CLK = '1') then

        if reg_operand1_we='1' then 
            reg_operand1 <= DI;
        elsif reg_operand2_we='1' then 
            reg_operand2 <= DI;
        end if;
    end if;
end process;

这会生成不同的硬件,并且还会产生不同的行为。

在没有elsif的示例中,当reg_operand2_we为高时,reg_operand2被分配DI,而不管reg_operand1_we的状态如何。

当使用elsif时,reg_operand2的赋值仅在reg_operand2_we为高且reg_operand1_we为低时发生

通常,如果两个赋值不相互依赖,请使用单独的if构造。

答案 1 :(得分:1)

第二个更短更简单,并将生成相同的硬件。 (从简短的检查:即假设一方或另一方没有意外的错别字)

第二个版本中的elsif,结合两个寄存器写入,将优先考虑寄存器;即如果您尝试通过在同一周期中置位we个信号来写入两个寄存器,则实际只会写入reg_operand1。它对设计没有任何其他影响。

因此...

除非您有特定的企业风格指南禁止它,否则请使用第二种风格作为一般规则。

在某些情况下,您可能需要完全分离某些功能,以明确它是独立的;在这种情况下,最好不要对这种风格说教;但通常情况下,更少的代码行意味着更少出错,尤其是在(如此处)更易于阅读和理解的地方。

“我在某处读到了”......值得知道你在哪里读到这篇文章。有很多令人难以忍受的坏书,教材和示例项目,等待破坏潜在的VHDL程序员,值得宣传哪些是为了避免...