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/] [modulus_ram_asym.vhd] - Blame information for rev 67

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

Line No. Rev Author Line
1 67 JonasDC
----------------------------------------------------------------------  
2
----  modulus_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 modulus, 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 modulus_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
----    - dpramblock_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
use mod_sim_exp.std_functions.all;
57
 
58
-- structural description of a RAM to hold the modulus, with 
59
-- adjustable width (64, 128, 256, 512, 576, 640,..) and depth(nr of moduluses)
60
--    formula for available widths: (i*512+(0 or 64 or 128 or 256)) (i=integer number) 
61
--
62
entity modulus_ram_asym is
63
  generic(
64
    width : integer := 1536;  -- must be a multiple of 32
65
    depth : integer := 2;     -- nr of moduluses
66
    device : string := "xilinx"
67
  );
68
  port(
69
    clk            : in std_logic;
70
      -- bus side
71
    write_modulus  : in std_logic; -- write enable
72
    modulus_in_sel : in std_logic_vector(log2(depth)-1 downto 0); -- modulus operand to write to
73
    modulus_addr   : in std_logic_vector(log2((width)/32)-1 downto 0); -- modulus word(32-bit) address
74
    modulus_in     : in std_logic_vector(31 downto 0); -- modulus word data in
75
    modulus_sel    : in std_logic_vector(log2(depth)-1 downto 0); -- selects the modulus to use for multiplications
76
      -- multiplier side
77
    modulus_out    : out std_logic_vector(width-1 downto 0)
78
  );
79
end modulus_ram_asym;
80
 
81
architecture structural of modulus_ram_asym is
82
  -- constants
83
  constant RAMblock_maxwidth   : integer := 512;
84
  constant nrRAMblocks_full    : integer := width/RAMblock_maxwidth;
85
  constant RAMblock_part       : integer := width rem RAMblock_maxwidth;
86
  constant RAMblock_part_width : integer := width-(nrRAMblocks_full*RAMblock_maxwidth);
87
  constant RAMselect_aw        : integer := log2(width/32)-log2(nrRAMblocks_full/32);
88
 
89
begin
90
 
91
  -- generate (width/512) ramblocks with a given depth
92
  -- these rams are tyed together to form the following structure
93
  --  dual port ram:
94
  --  - PORT A : 32-bit write
95
  --  - PORT B : (width)-bit read
96
  -- 
97
  single_block : if (width <= RAMblock_maxwidth) generate
98
    signal waddr : std_logic_vector(log2((width*depth)/32)-1 downto 0);
99
  begin
100
    waddr <= modulus_in_sel & modulus_addr;
101
 
102
    ramblock: entity mod_sim_exp.dpramblock_asym
103
    generic map(
104
      width => width,
105
      depth => depth,
106
      device  => device
107
    )
108
    port map(
109
      clk => clk,
110
      -- write port
111
      waddr => waddr,
112
      we    => write_modulus,
113
      din   => modulus_in,
114
      -- read port
115
      raddr => modulus_sel,
116
      dout  => modulus_out
117
    );
118
  end generate;
119
 
120
  multiple_full_blocks : if (width > RAMblock_maxwidth) generate
121
    -- signals for multiple blocks
122
    signal waddr  : std_logic_vector(log2(RAMblock_maxwidth*depth/32)-1 downto 0);
123
    signal we_RAM : std_logic_vector(nrRAMblocks_full-1 downto 0);
124
  begin
125
    ramblocks_full : for i in 0 to nrRAMblocks_full generate
126
      -- write port signal
127
      waddr <= modulus_in_sel & modulus_addr(log2(RAMblock_maxwidth/32)-1 downto 0);
128
 
129
      full_ones : if (i < nrRAMblocks_full) generate
130
        ramblock_full : entity mod_sim_exp.dpramblock_asym
131
        generic map(
132
          width  => RAMblock_maxwidth,
133
          depth  => depth,
134
          device => device
135
        )
136
        port map(
137
          clk => clk,
138
          -- write port
139
          waddr => waddr,
140
          we    => we_RAM(i),
141
          din   => modulus_in,
142
          -- read port
143
          raddr => modulus_sel,
144
          dout  => modulus_out((i+1)*RAMblock_maxwidth-1 downto i*RAMblock_maxwidth)
145
        );
146
        -- we
147
        process (write_modulus, modulus_addr)
148
        begin
149
          if modulus_addr(log2(width/32)-1 downto log2(RAMblock_maxwidth/32)) = conv_std_logic_vector(i,RAMselect_aw) then
150
            we_RAM(i) <= write_modulus;
151
          else
152
            we_RAM(i) <= '0';
153
          end if;
154
        end process;
155
      end generate; -- end of if generate for full blocks
156
 
157
      optional_part : if (i = nrRAMblocks_full) and (RAMblock_part /= 0) generate
158
        -- signals for optional part
159
        signal waddr_part : std_logic_vector(log2(RAMblock_part_width*depth/32)-1 downto 0);
160
        signal we_part    : std_logic;
161
      begin
162
        -- write port signal
163
        waddr_part <= modulus_in_sel & modulus_addr(log2(RAMblock_part_width/32)-1 downto 0);
164
        ramblock_part : entity mod_sim_exp.dpramblock_asym
165
        generic map(
166
          width  => RAMblock_part_width,
167
          depth  => depth,
168
          device => device
169
        )
170
        port map(
171
          clk => clk,
172
          -- write port
173
          waddr => waddr_part,
174
          we    => we_part,
175
          din   => modulus_in,
176
          -- read port
177
          raddr => modulus_sel,
178
          dout  => modulus_out(width-1 downto i*RAMblock_maxwidth)
179
        );
180
 
181
        -- we_part
182
        process (write_modulus, modulus_addr)
183
        begin
184
          if modulus_addr(log2(width/32)-1 downto log2(RAMblock_maxwidth/32)) = conv_std_logic_vector(i,RAMselect_aw) then
185
            we_part <= write_modulus;
186
          else
187
            we_part <= '0';
188
          end if;
189
        end process;
190
      end generate;-- end of if generate for part block
191
    end generate;-- end of for generate
192
  end generate;-- end of if generate for multiple blocks
193
 
194
end structural;

powered by: WebSVN 2.1.0

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