Intel® Quartus® Prime Pro Edition用户指南: 设计建议

ID 683082
日期 9/28/2020
Public

本文档可提供新的版本。客户应 单击此处 前往查看最新版本。

文档目录

1.4.1.9. 混合宽度双端口RAM

本节中的RAM代码示例显示SystemVerilog和VHDL代码,这些代码通过不同宽度的数据端口推断RAM。

Verilog-1995不支持混合宽度RAM,因为此标准缺少用于对不同的读取宽度和/或写入宽度进行建模的多维数组。Verilog-2001不支持混合宽度RAM,因为这种类型的逻辑需要多个封装尺寸。不同的综合工具对这些存储器的支持可能有所不同。本节描述 Intel® Quartus® Prime Pro Edition综合的推断规则。

多维封装阵列的第一维表示宽端口与窄端口的比率。第二维表示较窄的端口宽度。读取和写入端口的宽度必须指定目标器件中存储器模块支持的读取或写入比率。否则,综合工具不会推断RAM。

请参考 Intel® Quartus® Prime HDL模板来了解支持读写宽度组合的参数化示例。您还可以找到具有两个混合宽度读取端口和两个混合宽度写入端口的真双端口RAM的示例。

读取宽度小于写入宽度的SystemVerilog混合宽度RAM

module mixed_width_ram    // 256x32 write and 1024x8 read
(
		input [7:0] waddr,  
		input [31:0] wdata, 
		input we, clk,
		input [9:0] raddr,
		output logic [7:0] q
);
	logic [3:0][7:0] ram[0:255];
	always_ff@(posedge clk)
		begin
			if(we) ram[waddr] <= wdata;
			q <= ram[raddr / 4][raddr % 4];
		end
endmodule : mixed_width_ram

读取宽度大于写入宽度的SystemVerilog混合宽度RAM

module mixed_width_ram     // 1024x8 write and 256x32 read	
(	
		input [9:0] waddr,	
		input [31:0] wdata, 	
		input we, clk, 	
		input [7:0] raddr,	
		output logic [9:0] q	
);	
	logic [3:0][7:0] ram[0:255];	
	always_ff@(posedge clk)	
		 begin	
			if(we) ram[waddr / 4][waddr % 4] <= wdata;	
			q <= ram[raddr];	
		 end	
endmodule : mixed_width_ram

读取宽度小于写入宽度的VHDL混合宽度RAM

library ieee;	
use ieee.std_logic_1164.all;	
	
package ram_types is	
	type word_t is array (0 to 3) of std_logic_vector(7 downto 0);	
	type ram_t is array (0 to 255) of word_t;	
end ram_types;	
	
library ieee;	
use ieee.std_logic_1164.all;	
library work;	
use work.ram_types.all;	
	
entity mixed_width_ram is	
	port (	
		we, clk : in  std_logic;	
		waddr   : in  integer range 0 to 255;	
		wdata   : in  word_t;	
		raddr   : in  integer range 0 to 1023;	
		q       : out std_logic_vector(7 downto 0));	
end mixed_width_ram;	
	
architecture rtl of mixed_width_ram is	
	signal ram : ram_t; 	
begin  -- rtl	
	process(clk, we)	
	begin	
		if(rising_edge(clk)) then 	
			if(we = '1') then	
				ram(waddr) <= wdata;	
			end if;	
			q <= ram(raddr / 4 )(raddr mod 4);	
		end if;	
	end process;		
end rtl;

读取宽度大于写入宽度的VHDL混合宽度RAM

library ieee;
use ieee.std_logic_1164.all;

package ram_types is
	type word_t is array (0 to 3) of std_logic_vector(7 downto 0);
	type ram_t is array (0 to 255) of word_t;
end ram_types;

library ieee;
use ieee.std_logic_1164.all;
library work;
use work.ram_types.all;

entity mixed_width_ram is
	port (
		we, clk : in  std_logic;
		waddr   : in  integer range 0 to 1023;
		wdata   : in  std_logic_vector(7 downto 0);
		raddr   : in  integer range 0 to 255;
		q       : out word_t);
end mixed_width_ram;

architecture rtl of mixed_width_ram is
	signal ram : ram_t; 
begin  -- rtl
	process(clk, we)
	begin
		if(rising_edge(clk)) then 
			if(we = '1') then
				ram(waddr / 4)(waddr mod 4) <= wdata;
			end if;
			q <= ram(raddr);
		end if;
	end process; 
end rtl;