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_gen.vhd] - Blame information for rev 63

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

Line No. Rev Author Line
1 63 JonasDC
----------------------------------------------------------------------  
2
----  operand_ram_gen                                             ---- 
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 the store the operands           ----
10
----    for the montgomery multiplier                             ----            
11
----                                                              ---- 
12
----  Dependencies:                                               ----
13
----    - tdpram_generic                                          ----
14
----                                                              ----
15
----  Authors:                                                    ----
16
----      - Geoffrey Ottoy, DraMCo research group                 ----
17
----      - Jonas De Craene, JonasDC@opencores.org                ---- 
18
----                                                              ---- 
19
---------------------------------------------------------------------- 
20
----                                                              ---- 
21
---- Copyright (C) 2011 DraMCo research group and OPENCORES.ORG   ---- 
22
----                                                              ---- 
23
---- This source file may be used and distributed without         ---- 
24
---- restriction provided that this copyright statement is not    ---- 
25
---- removed from the file and that any derivative work contains  ---- 
26
---- the original copyright notice and the associated disclaimer. ---- 
27
----                                                              ---- 
28
---- This source file is free software; you can redistribute it   ---- 
29
---- and/or modify it under the terms of the GNU Lesser General   ---- 
30
---- Public License as published by the Free Software Foundation; ---- 
31
---- either version 2.1 of the License, or (at your option) any   ---- 
32
---- later version.                                               ---- 
33
----                                                              ---- 
34
---- This source is distributed in the hope that it will be       ---- 
35
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ---- 
36
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ---- 
37
---- PURPOSE.  See the GNU Lesser General Public License for more ---- 
38
---- details.                                                     ---- 
39
----                                                              ---- 
40
---- You should have received a copy of the GNU Lesser General    ---- 
41
---- Public License along with this source; if not, download it   ---- 
42
---- from http://www.opencores.org/lgpl.shtml                     ---- 
43
----                                                              ---- 
44
----------------------------------------------------------------------
45
 
46
library ieee;
47
use ieee.std_logic_1164.all;
48
use ieee.std_logic_arith.all;
49
use ieee.std_logic_unsigned.all;
50
 
51
library mod_sim_exp;
52
use mod_sim_exp.mod_sim_exp_pkg.all;
53
use mod_sim_exp.std_functions.all;
54
 
55
-- behavorial description of a RAM to hold the operands, with 
56
-- adjustable width and depth(nr of operands)
57
entity operand_ram_gen is
58
  generic(
59
    width : integer := 1536; -- width of the operands
60
    depth : integer := 4     -- nr of operands
61
  );
62
  port(
63
      -- global ports
64
    clk       : in std_logic;
65
    collision : out std_logic; -- 1 if simultaneous write on RAM
66
      -- bus side connections (32-bit serial)
67
    write_operand  : in std_logic; -- write_enable
68
    operand_in_sel : in std_logic_vector(log2(depth)-1 downto 0); -- operand to write to
69
    operand_addr   : in std_logic_vector(log2(width/32)-1 downto 0); -- address of operand word to write
70
    operand_in     : in std_logic_vector(31 downto 0);  -- operand word(32-bit) to write
71
    result_out     : out std_logic_vector(31 downto 0); -- operand out, reading is always result operand
72
    operand_out_sel : in std_logic_vector(log2(depth)-1 downto 0); -- operand to give to multiplier
73
      -- multiplier side connections (width-bit parallel)
74
    result_dest_op  : in std_logic_vector(log2(depth)-1 downto 0); -- operand select for result
75
    operand_out     : out std_logic_vector(width-1 downto 0); -- operand out to multiplier
76
    write_result    : in std_logic; -- write enable for multiplier side
77
    result_in       : in std_logic_vector(width-1 downto 0) -- result to write from multiplier
78
  );
79
end operand_ram_gen;
80
 
81
 
82
architecture Behavioral of operand_ram_gen is
83
  constant nrRAMs : integer := width/32;
84
  constant RAMselect_aw : integer := log2(nrRAMs);
85
  constant RAMdepth_aw : integer := log2(depth);
86
  constant total_aw : integer := RAMdepth_aw+RAMselect_aw;
87
 
88
  -- total RAM structure signals
89
  signal weA_RAM : std_logic_vector(nrRAMs-1 downto 0);
90
  type wordsplit is array (nrRAMs-1 downto 0) of std_logic_vector(31 downto 0);
91
  signal doutB_RAM : wordsplit;
92
  --- PORT A : 32-bit write | (width)-bit read
93
  signal dinA    : std_logic_vector(31 downto 0);
94
  signal doutA   : std_logic_vector(width-1 downto 0);
95
  signal weA     : std_logic;
96
  signal addrA   : std_logic_vector(RAMselect_aw-1 downto 0);
97
  signal op_selA : std_logic_vector(RAMdepth_aw-1 downto 0);
98
  --- PORT B : 32-bit read  | (width)-bit write
99
  signal dinB    : std_logic_vector(width-1 downto 0);
100
  signal doutB   : std_logic_vector(31 downto 0);
101
  signal weB     : std_logic;
102
  signal addrB   : std_logic_vector(RAMselect_aw-1 downto 0);
103
  signal op_selB : std_logic_vector(RAMdepth_aw-1 downto 0);
104
 
105
  signal write_operand_i : std_logic;
106
  signal op_selA_i : std_logic_vector(RAMdepth_aw-1 downto 0);
107
begin
108
 
109
        -- WARNING: Very Important!
110
  -- wea & web signals must never be high at the same time !!
111
  -- web has priority 
112
  write_operand_i <= write_operand and not write_result; -- portB has write priority
113
  collision <= write_operand and write_result;
114
 
115
  -- the dual port ram has a depth of 4 (each layer contains an operand)
116
  -- result is always stored in position 3
117
  -- doutb is always result
118
  with write_operand_i select
119
    op_selA_i <= operand_in_sel when '1',
120
                 operand_out_sel when others;
121
 
122
  -- map signals to RAM
123
  -- PORTA
124
  weA <= write_operand_i;
125
  op_selA <= op_selA_i;
126
  addrA <= operand_addr;
127
  dinA <= operand_in;
128
  operand_out <= doutA;
129
  -- PORT B
130
  weB <= write_result;
131
  op_selB <= result_dest_op; -- portB locked to result operand
132
  addrB <= operand_addr;
133
  dinB <= result_in;
134
  result_out <= doutB;
135
 
136
        -- generate (width/32) blocks of 32-bit ram with a given depth
137
  -- these rams are tyed together to form the following structure
138
  --  True dual port ram:
139
  --  - PORT A : 32-bit write | (width)-bit read
140
  --  - PORT B : 32-bit read  | (width)-bit write
141
  --                ^             ^
142
  -- addres       addr          op_sel
143
  -- 
144
  ramblocks : for i in 0 to nrRAMs-1 generate
145
    ramblock: tdpram_generic
146
    generic map(
147
      depth => depth
148
    )
149
    port map(
150
      -- port A : 32-bit
151
      clkA  => clk,
152
      addrA => op_selA,
153
      weA   => weA_RAM(i),
154
      dinA  => dinA,
155
      doutA => doutA(((i+1)*32)-1 downto i*32),
156
      -- port B : 32-bit
157
      clkB  => clk,
158
      addrB => op_selB,
159
      weB   => weB,
160
      dinB  => dinB(((i+1)*32)-1 downto i*32),
161
      doutB => doutB_RAM(i)
162
    );
163
    --    demultiplexer for write enable A signal
164
    process (addrA, weA)
165
    begin
166
      if addrA(RAMselect_aw-1 downto 0) = conv_std_logic_vector(i,RAMselect_aw) then
167
        weA_RAM(i) <= weA;
168
      else
169
        weA_RAM(i) <= '0';
170
      end if;
171
    end process;
172
  end generate;
173
  -- PORTB 32-bit read
174
  doutB <= doutB_RAM(conv_integer(addrB)) when (conv_integer(addrB)<nrRAMs)
175
          else (others=>'0');
176
 
177
end Behavioral;

powered by: WebSVN 2.1.0

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