User`s manual
Modeling memory in VHDL
C-294 Tips and Techniques ModelSim Xilinx User’s Manual
A simple alternative implementation provides some excellent performance
benefits:
• storage required to model the memory can be reduced by 1-2 orders of
magnitude
• startup and run times are reduced
• associated memory allocation errors are eliminated
The trick is to model memory using variables instead of signals.
In the example below, we illustrate three alternative architectures for entity
"memory". Architecture "style_87_bad" uses a vhdl signal to store the ram data.
Architecture "style_87" uses variables in the "memory" process, and architecture
"style_93" uses variables in the architecture.
For large memories, architecture "style_87_bad" runs many times longer than the
other two, and uses much more memory. This style should be avoided.
Both architectures "style_87" and "style_93" work with equal efficiently. You’ll
find some additional flexibility with the VHDL 1993 style, however, because the
ram storage can be shared between multiple processes. For example, a second
process is shown that initializes the memory; you could add other processes to
create a multi-ported memory.
To implement this model, you will need functions that convert vectors to integers.
To use it you will probably need to convert integers to vectors.
Example functions are provided below in package "conversions".
------------------------------------------------------------
------------------------------------------------------------
use std.standard.all;
library ieee;
use ieee.std_logic_1164.all;
use work.conversions.all;
entity memory is
generic(add_bits : integer := 12;
data_bits : integer := 32);
port(add_in : in std_ulogic_vector(add_bits-1 downto 0);
data_in : in std_ulogic_vector(data_bits-1 downto 0);
data_out : out std_ulogic_vector
(data_bits-1 downto 0);
cs, mwrite : in std_ulogic;
do_init : in std_ulogic);
subtype word is std_ulogic_vector(data_bits-1 downto 0);
constant nwords : integer := 2 ** add_bits;
type ram_type is array(0 to nwords-1) of word;
end;