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 90

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 90 JonasDC
    clk       : in std_logic;
65 63 JonasDC
    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 90 JonasDC
  signal doutB_RAM : wordsplit;
92 63 JonasDC
  --- PORT A : 32-bit write | (width)-bit read
93
  signal dinA    : std_logic_vector(31 downto 0);
94 90 JonasDC
  signal doutA   : std_logic_vector(width-1 downto 0);
95 63 JonasDC
  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 90 JonasDC
  signal doutB   : std_logic_vector(31 downto 0);
101 63 JonasDC
  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 90 JonasDC
  signal op_selA_i : std_logic_vector(RAMdepth_aw-1 downto 0);
107 63 JonasDC
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 90 JonasDC
  with write_operand_i select
119
    op_selA_i <= operand_in_sel when '1',
120 63 JonasDC
                 operand_out_sel when others;
121
 
122
  -- map signals to RAM
123
  -- PORTA
124
  weA <= write_operand_i;
125 90 JonasDC
  op_selA <= op_selA_i;
126 63 JonasDC
  addrA <= operand_addr;
127
  dinA <= operand_in;
128 90 JonasDC
  operand_out <= doutA;
129 63 JonasDC
  -- PORT B
130
  weB <= write_result;
131 90 JonasDC
  op_selB <= result_dest_op; -- portB locked to result operand
132 63 JonasDC
  addrB <= operand_addr;
133
  dinB <= result_in;
134 90 JonasDC
  result_out <= doutB;
135 63 JonasDC
 
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 90 JonasDC
  --  - PORT A : 32-bit write | (width)-bit read
140
  --  - PORT B : 32-bit read  | (width)-bit write
141 63 JonasDC
  --                ^             ^
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 90 JonasDC
      clkA  => clk,
152 63 JonasDC
      addrA => op_selA,
153
      weA   => weA_RAM(i),
154
      dinA  => dinA,
155 90 JonasDC
      doutA => doutA(((i+1)*32)-1 downto i*32),
156 63 JonasDC
      -- port B : 32-bit
157 90 JonasDC
      clkB  => clk,
158 63 JonasDC
      addrB => op_selB,
159
      weB   => weB,
160
      dinB  => dinB(((i+1)*32)-1 downto i*32),
161 90 JonasDC
      doutB => doutB_RAM(i)
162 63 JonasDC
    );
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 90 JonasDC
  doutB <= doutB_RAM(conv_integer(addrB)) when (conv_integer(addrB)<nrRAMs)
175 63 JonasDC
          else (others=>'0');
176
 
177
end Behavioral;

powered by: WebSVN 2.1.0

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