VHDL。比较器的性能

时间:2013-06-04 18:31:35

标签: performance vhdl modelsim

我在vhdl上创建小芯片块 - 比较器 使用:QuartusII,ModelSim,在Cyclone ii上模拟。

INPUT:  
    IN_FIRST: in UNSIGNED(255 downto 0);  
    IN_SECOND: in UNSIGNED(255 downto 0);  

OUTPUT:  
    OUT_IS_RIGHT_RESULT: out STD_LOGIC; -- IN_SECOND < IN_FIRST  

我有一些不同的并行和顺序实现。但并行在某些情况下比顺序更糟糕。 而且我找不到最佳方法。

一些不同的实现:

使用generate(time-18.5ns)

architecture ComparatorArch of Comparator is
    signal T: UNSIGNED(7 downto 0) := (others => 'U');
    signal H: UNSIGNED(7 downto 0) := (others => 'U');
begin
    generateG: for i in 7 downto 0 generate
        T(i) <= '1' when (IN_FIRST((i + 1) * 32 - 1 downto i * 32) > IN_SECOND((i + 1) * 32 - 1 downto i * 32)) else '0';
        H(i) <= '1' when (IN_FIRST((i + 1) * 32 - 1 downto i * 32) < IN_SECOND((i + 1) * 32 - 1 downto i * 32)) else '0';
    end generate generateG;

    OUT_TARG <= T;
    OUT_HASH <= H;
    OUT_IS_RIGHT_RESULT <= (T(7) or ((not T(7)) and ((not H(7)) and 
        (T(6) or ((not T(6)) and ((not H(6)) and 
        (T(5) or ((not T(5)) and ((not H(5)) and 
        (T(4) or ((not T(4)) and ((not H(4)) and 
        (T(3) or ((not T(3)) and ((not H(3)) and 
        (T(2) or ((not T(2)) and ((not H(2)) and 
        (T(1) or ((not T(1)) and ((not H(1)) and T(0))))))))))))))))))))));
end ComparatorArch;

最后一部分 - 它是比较TH的逻辑表示。

正在处理中(时间为35ns)

architecture ComparatorArch of Comparator is
begin
  mainP: process(IN_READY) begin
        if (rising_edge(IN_READY) and IN_READY = '1') then
            if (IN_SECOND < IN_FIRST) then
                OUT_IS_RIGHT_RESULT <= '1';
            else
                OUT_IS_RIGHT_RESULT <= '0';
            end if;
        end if;
  end process;
end ComparatorArch;

可能有人知道更好的方法。

如果我改变

它就不起作用
if (rising_edge(IN_READY) and IN_READY = '1') then  

if (IN_READY = '1') then  

为什么呢?

我研究了一些基本的例子,并意识到芯片具有特殊输入数据大小的逻辑和计算块。 它比较或计算大小从min到特定最大值的信号的逻辑运算const time。 它将BIT / BIT或BIT_VECTOR(7降至0)/ BIT_VECTOR(7降至0)同时进行比较 - 约为9ns。为什么这么长时间?有人可以解释一下吗?

1 个答案:

答案 0 :(得分:1)

如前所述,当您扩展比较器时,并行树将具有最佳性能。然而,对于窄至8位的比较器,路由延迟可以占主导地位,并且Cyclone II将使用其进位链表现更好(参见Cyclone II device handbook的第2-2节),因为它们直接连接到相邻的LE。这就是串行逻辑可以胜过并行的原因。

至于rising_edge,你写了两个约定的混合。在使用rising_edge标准之前,使用clk'event and event='1'执行相同的功能;由于rising_edge已将新状态定义为“1”,因此无需对其进行测试。另一方面,单独测试高级别 不会产生D flip-flop而是产生transparent latch - 大多数FPGA未被优化的很少需要的功能,以及综合工具倾向于警告这一点。

至于你的计时结果,没有看到测试方法我从你提到的时候就看不到任何东西。甚至是关于拟合后模拟?对于如此小的功能而言,这种情况很难达到。