gpt4 book ai didi

VHDL:通过同步读取推断单端口 ram 的正确方法

转载 作者:行者123 更新时间:2023-12-05 02:11:32 25 4
gpt4 key购买 nike

多年来我一直在争论这个问题......为什么要推断具有同步读取的单端口 ram 的正确原因是什么。

假设我在 VHDL 中推断内存的接口(interface)是:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity sram1 is
generic(
aw :integer := 8; --address width of memory
dw :integer := 8 --data width of memory
);
port(
--arm clock
aclk :in std_logic;
aclear :in std_logic;

waddr :in std_logic_vector(aw-1 downto 0);
wdata :in std_logic_vector(dw-1 downto 0);
wen :in std_logic;

raddr :in std_logic_vector(aw-1 downto 0);
rdata :out std_logic_vector(dw-1 downto 0)
);
end entity;

是这样的:1 号门

-- I LIKE THIS ONE
architecture rtl of sram1 is
constant mem_len :integer := 2**aw;

type mem_type is array (0 to mem_len-1) of std_logic_vector(dw-1 downto 0);

signal block_ram : mem_type := (others => (others => '0'));

begin

process(aclk)
begin
if (rising_edge(aclk)) then
if (wen = '1') then
block_ram(to_integer(unsigned(waddr))) <= wdata(dw-1 downto 0);
end if;

-- QUESTION: REGISTERING THE READ DATA (ALL OUTPUT REGISTERED)?
rdata <= block_ram(to_integer(unsigned(raddr)));

end if;
end process;


end architecture;

或者这样:2 号门

-- TEXTBOOKS LIKE THIS ONE
architecture rtl of sram1 is
constant mem_len :integer := 2**aw;

type mem_type is array (0 to mem_len-1) of std_logic_vector(dw-1 downto 0);

signal block_ram : mem_type := (others => (others => '0'));
signal raddr_dff : std_logic_vector(aw-1 downto 0);

begin

process(aclk)
begin
if (rising_edge(aclk)) then
if (wen = '1') then
block_ram(to_integer(unsigned(waddr))) <= wdata(dw-1 downto 0);
end if;

-- QUESTION: REGISTERING THE READ ADDRESS?
raddr_dff <= raddr;

end if;
end process;

-- QUESTION: HOT ADDRESS SELECTION OF DATA
rdata <= block_ram(to_integer(unsigned(raddr_dff)));

end architecture;

我是第一个版本的粉丝,因为我认为注册 vhdl 模块的所有输出是一种很好的做法。然而,许多教科书将后来的版本列为推断具有同步读取的单端口 ram 的正确方法。

从 Xilinx 或 Altera 综合的角度来看,这真的重要吗,只要您已经考虑到延迟数据与地址之间的差异(并确定这对您的应用无关紧要。)

我的意思是...他们仍然在 FPGA 中为您提供 block 内存?正确的?

或者一个给你 LUTS 而另一个给你 Block ram?

哪个会在 FPGA 中推断出更好的时序和更好的容量,door #1 还是 door #2?

最佳答案

不幸的是,综合工具供应商已经制作了 RAM 推理功能,因此他们通常可以识别这两种样式,而不管所讨论的 FPGA 中 RAM 的物理实现如何。因此,即使您指定了注册输出,syntesis 工具也可能会默默地忽略它并推断出具有注册输入的 RAM。这在功能上并不等同,因此它实际上可能会导致不良行为,特别是在双端口 RAM 的情况下。

为避免此陷阱,您可以添加特定于供应商的属性,告诉综合工具您需要哪种 RAM。

一般来说,大多数 FPGA 在物理 RAM 上都有强制注册的输入,并且可以在输出上添加一个额外的可选寄存器。因此,使用带有注册输入的代码样式代码可能会使模拟与现实相匹配,这通常是一件好事。

关于VHDL:通过同步读取推断单端口 ram 的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57435602/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com