Guest User

Untitled

a guest
May 11th, 2025
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.67 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.NUMERIC_STD.ALL;
  4.  
  5. entity AssociativeMemory is
  6.     Port (
  7.         clk       : in  STD_LOGIC;
  8.         we        : in  STD_LOGIC;
  9.         am_addr      : in  STD_LOGIC_VECTOR(15 downto 0);  -- 13 Bit für 8192+ Einträge
  10.         am_data_in   : in  STD_LOGIC_VECTOR(31 downto 0);
  11.         am_data_out  : out STD_LOGIC_VECTOR(31 downto 0)
  12.     );
  13. end AssociativeMemory;
  14.  
  15. architecture Behavioral of AssociativeMemory is
  16.     constant VECTOR_WIDTH   : integer := 10000;
  17.     constant WORD_WIDTH     : integer := 32;
  18.     constant NUM_VECTORS    : integer := 5;
  19.     constant CHUNKS_PER_VEC : integer := (VECTOR_WIDTH + WORD_WIDTH - 1) / WORD_WIDTH;  -- 313
  20.     constant MEM_DEPTH      : integer := CHUNKS_PER_VEC * NUM_VECTORS;  -- 32 * 313 = 10016
  21.  
  22.     type memory_array is array (0 to MEM_DEPTH - 1) of std_logic_vector(WORD_WIDTH - 1 downto 0);
  23.     signal memory : memory_array := (others => (others => '0'));
  24.  
  25.     attribute ram_style : string;
  26.     attribute ram_style of memory : signal is "block";
  27. begin
  28.     process(clk)
  29.     variable addr_int : integer;
  30.     begin
  31.         if rising_edge(clk) then
  32.             addr_int := to_integer(unsigned(am_addr));
  33.             if addr_int < MEM_DEPTH then
  34.                 if we = '1' then
  35.                     memory(addr_int) <= am_data_in;
  36.                 end if;
  37.                 am_data_out <= memory(addr_int);
  38.             else
  39.                 report "Invalid memory access at addr = " & integer'image(addr_int)
  40.                     severity failure;
  41.                 am_data_out <= (others => '0'); -- Fallback
  42.             end if;
  43.         end if;
  44.     end process;
  45.    
  46. end Behavioral;
  47.  
Add Comment
Please, Sign In to add comment