OpenCores
URL https://opencores.org/ocsvn/mod_sim_exp/mod_sim_exp/trunk

Subversion Repositories mod_sim_exp

[/] [mod_sim_exp/] [trunk/] [rtl/] [vhdl/] [core/] [operand_ram_asym.vhd] - Blame information for rev 81

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 67 JonasDC
----------------------------------------------------------------------  
2
----  operand_ram_asym                                            ---- 
3
----                                                              ---- 
4
----  This file is part of the                                    ----
5
----    Modular Simultaneous Exponentiation Core project          ---- 
6
----    http://www.opencores.org/cores/mod_sim_exp/               ---- 
7
----                                                              ---- 
8
----  Description                                                 ---- 
9
----    BRAM memory and logic to store the operands, due to the   ----
10
----    achitecture, a minimum depth of 2 is needed for this      ----
11
----    module to be inferred into blockram, this version is      ----
12
----    slightly more performant than operand_ram_gen and uses    ----
13
----    less resources. but does not work on every fpga, only     ----
14
----    the ones that support asymmetric rams.                    ----           
15
----                                                              ---- 
16
----  Dependencies:                                               ----
17
----    - tdpramblock_asym                                        ----
18
----                                                              ----
19
----  Authors:                                                    ----
20
----      - Geoffrey Ottoy, DraMCo research group                 ----
21
----      - Jonas De Craene, JonasDC@opencores.org                ---- 
22
----                                                              ---- 
23
---------------------------------------------------------------------- 
24
----                                                              ---- 
25
---- Copyright (C) 2011 DraMCo research group and OPENCORES.ORG   ---- 
26
----                                                              ---- 
27
---- This source file may be used and distributed without         ---- 
28
---- restriction provided that this copyright statement is not    ---- 
29
---- removed from the file and that any derivative work contains  ---- 
30
---- the original copyright notice and the associated disclaimer. ---- 
31
----                                                              ---- 
32
---- This source file is free software; you can redistribute it   ---- 
33
---- and/or modify it under the terms of the GNU Lesser General   ---- 
34
---- Public License as published by the Free Software Foundation; ---- 
35
---- either version 2.1 of the License, or (at your option) any   ---- 
36
---- later version.                                               ---- 
37
----                                                              ---- 
38
---- This source is distributed in the hope that it will be       ---- 
39
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ---- 
40
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ---- 
41
---- PURPOSE.  See the GNU Lesser General Public License for more ---- 
42
---- details.                                                     ---- 
43
----                                                              ---- 
44
---- You should have received a copy of the GNU Lesser General    ---- 
45
---- Public License along with this source; if not, download it   ---- 
46
---- from http://www.opencores.org/lgpl.shtml                     ---- 
47
----                                                              ---- 
48
----------------------------------------------------------------------
49
 
50
library ieee;
51
use ieee.std_logic_1164.all;
52
use ieee.std_logic_arith.all;
53
use ieee.std_logic_unsigned.all;
54
 
55
library mod_sim_exp;
56 81 JonasDC
use mod_sim_exp.mod_sim_exp_pkg.all;
57 67 JonasDC
use mod_sim_exp.std_functions.all;
58
 
59
-- structural description of a RAM to hold the operands, with 
60
-- adjustable width (64, 128, 256, 512, 576, 640,..) and depth(nr of operands)
61
--    formula for available widths: (i*512+(0 or 64 or 128 or 256)) (i=integer number) 
62
--
63
entity operand_ram_asym is
64
  generic(
65
    width  : integer := 1536; -- width of the operands
66
    depth  : integer := 4;    -- nr of operands
67
    device : string  := "xilinx"
68
  );
69
  port(
70
      -- global ports
71
    clk       : in std_logic;
72
    collision : out std_logic; -- 1 if simultaneous write on RAM
73
      -- bus side connections (32-bit serial)
74
    write_operand  : in std_logic; -- write_enable
75
    operand_in_sel : in std_logic_vector(log2(depth)-1 downto 0); -- operand to write to
76
    operand_addr   : in std_logic_vector(log2(width/32)-1 downto 0); -- address of operand word to write
77
    operand_in     : in std_logic_vector(31 downto 0);  -- operand word(32-bit) to write
78
    result_out     : out std_logic_vector(31 downto 0); -- operand out, reading is always result operand
79
    operand_out_sel : in std_logic_vector(log2(depth)-1 downto 0); -- operand to give to multiplier
80
      -- multiplier side connections (width-bit parallel)
81
    result_dest_op  : in std_logic_vector(log2(depth)-1 downto 0); -- operand select for result
82
    operand_out     : out std_logic_vector(width-1 downto 0); -- operand out to multiplier
83
    write_result    : in std_logic; -- write enable for multiplier side
84
    result_in       : in std_logic_vector(width-1 downto 0) -- result to write from multiplier
85
  );
86
end operand_ram_asym;
87
 
88
architecture Behavioral of operand_ram_asym is
89
  -- contstants
90
  constant RAMblock_maxwidth   : integer := 512;
91
  constant nrRAMblocks_full    : integer := width/RAMblock_maxwidth;
92
  constant RAMblock_part       : integer := width rem RAMblock_maxwidth;
93
  constant RAMblock_part_width : integer := width-(nrRAMblocks_full*RAMblock_maxwidth);
94
  constant RAMselect_aw        : integer := log2(width/32)-log2(nrRAMblocks_full/32);
95
 
96
  -- internal signals
97
  signal mult_op_sel     : std_logic_vector(log2(depth)-1 downto 0);
98
  signal write_operand_i : std_logic;
99
begin
100
  -- WARNING: Very Important!
101
  -- wea & web signals must never be high at the same time !!
102
  -- web has priority 
103
  write_operand_i <= write_operand and not write_result; -- portB has write priority
104
  collision <= write_operand and write_result;
105
 
106
  -- when multiplier is writing back result, select the result address
107
  with write_result select
108
  mult_op_sel <= result_dest_op when '1',
109
                 operand_out_sel when others;
110
 
111
  -- generate (width/512) ramblocks with a given depth
112
  -- these rams are tyed together to form the following structure
113
  --  True dual port ram:
114
  --  - PORT A : 32-bit write      | 32-bit read
115
  --  - PORT B : (width)-bit write | (width)-bit read
116
  -- 
117
  single_block : if (width <= RAMblock_maxwidth) generate
118
    -- signals for single block
119
    signal addrA_single : std_logic_vector(log2(width*depth/32)-1 downto 0);
120
  begin
121
    addrA_single <= operand_in_sel & operand_addr;
122 81 JonasDC
    ramblock : tdpramblock_asym
123 67 JonasDC
    generic map(
124
      depth  => depth,
125
      width  => width,
126
      device => device
127
    )
128
    port map(
129
      clk => clk,
130
      -- port A 32-bit
131
      addrA => addrA_single,
132
      weA   => write_operand_i,
133
      dinA  => operand_in,
134
      doutA => result_out,
135
      -- port B (width)-bit
136
      addrB => mult_op_sel,
137
      weB   => write_result,
138
      dinB  => result_in,
139
      doutB => operand_out
140
    );
141
  end generate;
142
 
143
  multiple_full_blocks : if (width > RAMblock_maxwidth) generate
144
    -- signals for multiple blocks
145
    type wordsplit is array (nrRAMblocks_full downto 0) of std_logic_vector(31 downto 0);
146
    signal doutA_RAM  : wordsplit;
147
    signal addrA      : std_logic_vector(log2(RAMblock_maxwidth*depth/32)-1 downto 0);
148
    signal weA_RAM    : std_logic_vector(nrRAMblocks_full-1 downto 0);
149
  begin
150
    ramblocks_full : for i in 0 to nrRAMblocks_full generate
151
      -- port A signals
152
      addrA <= operand_in_sel & operand_addr(log2(RAMblock_maxwidth/32)-1 downto 0);
153
 
154
      full_ones : if (i < nrRAMblocks_full) generate
155 81 JonasDC
        ramblock_full : tdpramblock_asym
156 67 JonasDC
        generic map(
157
          depth  => depth,
158
          width  => RAMblock_maxwidth,
159
          device => device
160
        )
161
        port map(
162
          clk => clk,
163
          -- port A 32-bit
164
          addrA => addrA,
165
          weA   => weA_RAM(i),
166
          dinA  => operand_in,
167
          doutA => doutA_RAM(i),
168
          -- port B (width)-bit
169
          addrB => mult_op_sel,
170
          weB   => write_result,
171
          dinB  => result_in((i+1)*RAMblock_maxwidth-1 downto i*RAMblock_maxwidth),
172
          doutB => operand_out((i+1)*RAMblock_maxwidth-1 downto i*RAMblock_maxwidth)
173
        );
174
        -- weA, weB
175 69 JonasDC
        process (write_operand_i, operand_addr)
176 67 JonasDC
        begin
177
          if operand_addr(log2(width/32)-1 downto log2(RAMblock_maxwidth/32)) = conv_std_logic_vector(i,RAMselect_aw) then
178
            weA_RAM(i) <= write_operand_i;
179
          else
180
            weA_RAM(i) <= '0';
181
          end if;
182
        end process;
183
        only_once : if (i = 0) generate
184
          -- port A read mux
185
          only_full_blocks : if (RAMblock_part = 0) generate
186
            result_out <= doutA_RAM(conv_integer(operand_addr(log2(width/32)-1 downto log2(RAMblock_maxwidth/32))))
187
                              when (conv_integer(operand_addr(log2(width/32)-1 downto log2(RAMblock_maxwidth/32)))<nrRAMblocks_full)
188
                          else (others=>'0');
189
          end generate;
190
          with_extra_part : if (RAMblock_part /= 0) generate
191
            result_out <= doutA_RAM(conv_integer(operand_addr(log2(width/32)-1 downto log2(RAMblock_maxwidth/32))))
192
                              when (conv_integer(operand_addr(log2(width/32)-1 downto log2(RAMblock_maxwidth/32)))<nrRAMblocks_full+1)
193
                          else (others=>'0');
194
          end generate;
195
        end generate;
196
      end generate;
197
 
198
      optional_part : if (i = nrRAMblocks_full) and (RAMblock_part /= 0) generate
199
        -- signals for part
200
        signal addrA_part : std_logic_vector(log2(RAMblock_part_width*depth/32)-1 downto 0);
201
        signal weA_part   : std_logic;
202
      begin
203
        addrA_part <= operand_in_sel & operand_addr(log2(RAMblock_part_width/32)-1 downto 0);
204 81 JonasDC
        ramblock_part : tdpramblock_asym
205 67 JonasDC
        generic map(
206
          depth  => depth,
207
          width  => RAMblock_part_width,
208
          device => device
209
        )
210
        port map(
211
          clk => clk,
212
          -- port A 32-bit
213
          addrA => addrA_part,
214
          weA   => weA_part,
215
          dinA  => operand_in,
216
          doutA => doutA_RAM(i),
217
          -- port B (width)-bit
218
          addrB => mult_op_sel,
219
          weB   => write_result,
220
          dinB  => result_in(width-1 downto i*RAMblock_maxwidth),
221
          doutB => operand_out(width-1 downto i*RAMblock_maxwidth)
222
        );
223
        -- weA, weB part
224 69 JonasDC
        process (write_operand_i, operand_addr)
225 67 JonasDC
        begin
226
          if operand_addr(log2(width/32)-1 downto log2(RAMblock_maxwidth/32)) = conv_std_logic_vector(i,RAMselect_aw) then
227
            weA_part <= write_operand_i;
228
          else
229
            weA_part <= '0';
230
          end if;
231
        end process;
232
      end generate;
233
    end generate;
234
  end generate;
235
 
236
end Behavioral;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.