【发布时间】:2014-03-13 19:15:07
【问题描述】:
我是 VHDL 新手,我的任务之一是创建一个 8 位寄存器文件。我注意到通过更改一行代码,我可以显着增加或减少逻辑元素的总数。我试图理解为什么这会导致如此重大的变化。
当enable 为高电平时,寄存器文件将dataIn 的值存储在selectWrite 的位置。 dataOut 显示存储在selectRead 位置的值。
如果dataOut <= entry(readIndex); 放在process(clock) 内部,则使用的逻辑元素总数为:
Total logical elements: 9/33,216 ( < 1% )
Total combinatorial functions 9/33,216 ( < 1% )
Dedicated logic registers 0/33,216 ( 0% )
但是,如果将dataOut <= entry(readIndex); 放在process(clock) 之外,则会使用数千个逻辑元素:
Total logical elements: 2,672/33,216 ( 8% )
Total combinatorial functions 1,656/33,216 ( 5% )
Dedicated logic registers 2,048/33,216 ( 6% )
我知道当放置在process(clock) 内部时,dataOut 只会在时钟沿发生变化,而当放置在process(clock) 外部时,dataOut 会发生不可预测的变化。
为什么这种变化会导致使用更多的逻辑元素?
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity RegisterFile is
port(
clock : in std_logic;
reset : in std_logic;
dataIn : in std_logic_vector(7 downto 0);
enable : in std_logic;
selectRead : in std_logic_vector(7 downto 0);
selectWrite : in std_logic_vector(7 downto 0);
dataOut : out std_logic_vector(7 downto 0)
);
end RegisterFile;
architecture RegisterFileArchitecture of RegisterFile is
type RegisterEntry is array (0 to 255) of std_logic_vector(7 downto 0);
signal entry : RegisterEntry;
signal readIndex : integer;
signal writeIndex : integer;
begin
-- Update read/write indices
readIndex <= to_integer(unsigned(selectRead));
writeIndex <= to_integer(unsigned(selectWrite));
process(clock)
begin
if (rising_edge(clock)) then
-- Update selected data
dataOut <= entry(readIndex);
if (reset = '1') then
entry(writeIndex) <= "00000000";
elsif (enable = '1') then
entry(writeIndex) <= dataIn;
end if;
end if;
end process;
end RegisterFileArchitecture;
【问题讨论】:
-
同步与异步读取。您可能会在合成报告 (.syr) 中找到有关合成器推断 RAM 以满足不同要求的方式的信息。我猜“较小”的也使用了 RAM 块......
-
我同意布赖恩的观点......但是,一些合成器将使用 RAM 实现这两个版本(例如 ISE 13.4),因此导致或多或少相同的大小。附加提示:使用范围定义您的索引信号(例如,信号 readIndex :整数范围 0 到 255 := 0),否则 32 位信号用于整数!
标签: vhdl