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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 JonasDC
----------------------------------------------------------------------  
2 24 JonasDC
----  mod_sim_exp_core                                            ---- 
3 3 JonasDC
----                                                              ---- 
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
----    toplevel of a modular simultaneous exponentiation core    ----
10
----    using a pipelined montgommery multiplier with split       ----
11 24 JonasDC
----    pipeline and auto-run support                             ----
12 3 JonasDC
----                                                              ----
13
----  Dependencies:                                               ----
14
----    - mont_mult_sys_pipeline                                  ----
15
----    - operand_mem                                             ----
16
----    - fifo_primitive                                          ----
17
----    - mont_ctrl                                               ----
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 2 JonasDC
 
50 3 JonasDC
library ieee;
51
use ieee.std_logic_1164.all;
52
use ieee.std_logic_arith.all;
53
use ieee.std_logic_unsigned.all;
54 2 JonasDC
 
55 3 JonasDC
library mod_sim_exp;
56
use mod_sim_exp.mod_sim_exp_pkg.all;
57 63 JonasDC
use mod_sim_exp.std_functions.all;
58 3 JonasDC
 
59 24 JonasDC
-- toplevel of the modular simultaneous exponentiation core
60
-- contains an operand and modulus ram, multiplier, an exponent fifo
61
-- and control logic
62
entity mod_sim_exp_core is
63 43 JonasDC
  generic(
64
    C_NR_BITS_TOTAL   : integer := 1536;
65
    C_NR_STAGES_TOTAL : integer := 96;
66
    C_NR_STAGES_LOW   : integer := 32;
67 63 JonasDC
    C_SPLIT_PIPELINE  : boolean := true;
68 94 JonasDC
    C_FIFO_AW         : integer := 7;      -- Address width for FIFO pointers
69 75 JonasDC
    C_MEM_STYLE       : string  := "asym"; -- xil_prim, generic, asym are valid options
70 84 JonasDC
    C_FPGA_MAN        : string  := "xilinx"   -- xilinx, altera are valid options
71 43 JonasDC
  );
72 3 JonasDC
  port(
73 94 JonasDC
    core_clk : in  std_logic;
74
    reset    : in  std_logic;
75 3 JonasDC
      -- operand memory interface (plb shared memory)
76 94 JonasDC
    bus_clk      : in  std_logic;
77 24 JonasDC
    write_enable : in  std_logic; -- write data to operand ram
78
    data_in      : in  std_logic_vector (31 downto 0);  -- operand ram data in
79 74 JonasDC
    rw_address   : in  std_logic_vector (8 downto 0); -- operand ram address bus
80 24 JonasDC
    data_out     : out std_logic_vector (31 downto 0);  -- operand ram data out
81
    collision    : out std_logic; -- write collision
82 3 JonasDC
      -- op_sel fifo interface
83 24 JonasDC
    fifo_din    : in  std_logic_vector (31 downto 0); -- exponent fifo data in
84
    fifo_push   : in  std_logic;  -- push data in exponent fifo
85
    fifo_full   : out std_logic;  -- high if fifo is full
86
    fifo_nopush : out std_logic;  -- high if error during push
87
      -- control signals
88
    start          : in  std_logic; -- start multiplication/exponentiation
89 45 JonasDC
    exp_m          : in  std_logic; -- single multiplication if low, exponentiation if high
90 24 JonasDC
    ready          : out std_logic; -- calculations done
91 74 JonasDC
    x_sel_single   : in  std_logic_vector (1 downto 0); -- single multiplication x operand selection
92
    y_sel_single   : in  std_logic_vector (1 downto 0); -- single multiplication y operand selection
93
    dest_op_single : in  std_logic_vector (1 downto 0); -- result destination operand selection
94 24 JonasDC
    p_sel          : in  std_logic_vector (1 downto 0); -- pipeline part selection
95 63 JonasDC
    calc_time      : out std_logic;
96 74 JonasDC
    modulus_sel    : in  std_logic   -- selects which modulus to use for multiplications
97 3 JonasDC
  );
98 24 JonasDC
end mod_sim_exp_core;
99 2 JonasDC
 
100 3 JonasDC
 
101 24 JonasDC
architecture Structural of mod_sim_exp_core is
102 74 JonasDC
  -- constants
103
  constant nr_op : integer := 4;
104
  constant nr_m  : integer := 2;
105
 
106 24 JonasDC
  -- data busses
107 69 JonasDC
  signal xy : std_logic_vector(C_NR_BITS_TOTAL-1 downto 0);  -- x and y operand data bus RAM -> multiplier
108
  signal m  : std_logic_vector(C_NR_BITS_TOTAL-1 downto 0);  -- modulus data bus RAM -> multiplier
109
  signal r  : std_logic_vector(C_NR_BITS_TOTAL-1 downto 0);  -- result data bus RAM <- multiplier
110
 
111 24 JonasDC
  -- control signals
112 69 JonasDC
  signal op_sel         : std_logic_vector(1 downto 0); -- operand selection
113
  signal result_dest_op : std_logic_vector(1 downto 0); -- result destination operand
114
  signal mult_ready     : std_logic;
115
  signal start_mult     : std_logic;
116 24 JonasDC
  signal load_x         : std_logic;
117 69 JonasDC
  signal load_result    : std_logic;
118 74 JonasDC
  signal modulus_sel_i  : std_logic_vector(0 downto 0);
119 94 JonasDC
  signal core_ready     : std_logic;
120
  signal core_calc_time : std_logic;
121
  signal core_collision : std_logic;
122
  signal core_start     : std_logic;
123 69 JonasDC
 
124 24 JonasDC
  -- fifo signals
125 3 JonasDC
  signal fifo_empty : std_logic;
126
  signal fifo_pop   : std_logic;
127
  signal fifo_nopop : std_logic;
128
  signal fifo_dout  : std_logic_vector(31 downto 0);
129 2 JonasDC
begin
130 84 JonasDC
  -- check the parameters
131
  assert (C_MEM_STYLE="xil_prim" or C_MEM_STYLE="generic" or C_MEM_STYLE="asym")
132
    report "C_MEM_STYLE incorrect!, it must be one of these: xil_prim, generic or asym" severity failure;
133
  assert (C_FPGA_MAN="xilinx" or C_FPGA_MAN="altera")
134
    report "C_FPGA_MAN incorrect!, it must be one of these: xilinx or altera" severity failure;
135 3 JonasDC
 
136
  -- Block ram memory for storing the operands and the modulus
137 69 JonasDC
  the_memory : operand_mem
138 34 JonasDC
  generic map(
139 69 JonasDC
    width     => C_NR_BITS_TOTAL,
140 74 JonasDC
    nr_op     => nr_op,
141
    nr_m      => nr_m,
142 69 JonasDC
    mem_style => C_MEM_STYLE,
143 84 JonasDC
    device    => C_FPGA_MAN
144 34 JonasDC
  )
145 24 JonasDC
  port map(
146 94 JonasDC
    bus_clk        => bus_clk,
147 3 JonasDC
    data_in        => data_in,
148
    data_out       => data_out,
149
    rw_address     => rw_address,
150 39 JonasDC
    write_enable   => write_enable,
151 3 JonasDC
    op_sel         => op_sel,
152 24 JonasDC
    xy_out         => xy,
153 3 JonasDC
    m              => m,
154 94 JonasDC
    core_clk       => core_clk,
155 3 JonasDC
    result_in      => r,
156
    load_result    => load_result,
157 24 JonasDC
    result_dest_op => result_dest_op,
158 94 JonasDC
    collision      => core_collision,
159 74 JonasDC
    modulus_sel    => modulus_sel_i
160 3 JonasDC
  );
161 39 JonasDC
 
162 74 JonasDC
  modulus_sel_i(0) <= modulus_sel;
163 45 JonasDC
        result_dest_op <= dest_op_single when exp_m = '0' else "11"; -- in autorun mode we always store the result in operand3
164 2 JonasDC
 
165 69 JonasDC
  -- A fifo for exponentiation mode
166 90 JonasDC
  xil_prim_fifo : if C_MEM_STYLE="xil_prim" generate
167 69 JonasDC
    the_exponent_fifo : fifo_primitive
168
    port map(
169 94 JonasDC
      push_clk => bus_clk,
170
      pop_clk => core_clk,
171 69 JonasDC
      din    => fifo_din,
172
      dout   => fifo_dout,
173
      empty  => fifo_empty,
174
      full   => fifo_full,
175
      push   => fifo_push,
176
      pop    => fifo_pop,
177
      reset  => reset,
178
      nopop  => fifo_nopop,
179
      nopush => fifo_nopush
180
    );
181 90 JonasDC
  end generate;
182 94 JonasDC
  gen_fifo : if (C_MEM_STYLE = "generic") or (C_MEM_STYLE = "asym") generate
183 97 JonasDC
    the_exponent_fifo : entity mod_sim_exp.generic_fifo_dc_gray
184 90 JonasDC
    generic map(
185 94 JonasDC
      dw => 32,
186
      aw => C_FIFO_AW
187 90 JonasDC
    )
188
    port map(
189 94 JonasDC
      wr_clk => bus_clk,
190
      rd_clk => core_clk,
191 90 JonasDC
      din    => fifo_din,
192
      dout   => fifo_dout,
193
      empty  => fifo_empty,
194
      full   => fifo_full,
195 94 JonasDC
      we     => fifo_push,
196
      re     => fifo_pop,
197
      clr    => reset,
198 90 JonasDC
      nopop  => fifo_nopop,
199
      nopush => fifo_nopush
200
    );
201
  end generate;
202 69 JonasDC
 
203 94 JonasDC
  -- The actual multiplier
204
  the_multiplier : mont_multiplier
205
  generic map(
206
    n     => C_NR_BITS_TOTAL,
207
    t     => C_NR_STAGES_TOTAL,
208
    tl    => C_NR_STAGES_LOW,
209
    split => C_SPLIT_PIPELINE
210
  )
211
  port map(
212
    core_clk => core_clk,
213
    xy       => xy,
214
    m        => m,
215
    r        => r,
216
    start    => start_mult,
217
    reset    => reset,  -- asynchronious reset
218
    p_sel    => p_sel,
219
    load_x   => load_x,
220
    ready    => mult_ready
221
  );
222
 
223 3 JonasDC
  -- The control logic for the core
224 24 JonasDC
  the_control_unit : mont_ctrl
225
  port map(
226 94 JonasDC
    clk              => core_clk,
227
    reset            => reset, -- asynchronious reset
228
    start            => core_start,
229 3 JonasDC
    x_sel_single     => x_sel_single,
230
    y_sel_single     => y_sel_single,
231 45 JonasDC
    run_auto         => exp_m,
232 3 JonasDC
    op_buffer_empty  => fifo_empty,
233
    op_sel_buffer    => fifo_dout,
234
    read_buffer      => fifo_pop,
235 94 JonasDC
    done             => core_ready,
236
    calc_time        => core_calc_time,
237 3 JonasDC
    op_sel           => op_sel,
238 24 JonasDC
    load_x           => load_x,
239 3 JonasDC
    load_result      => load_result,
240
    start_multiplier => start_mult,
241
    multiplier_ready => mult_ready
242
  );
243 94 JonasDC
 
244
  -- go from bus clock domain to core clock domain
245
  start_pulse : pulse_cdc
246
  port map(
247
    reset  => reset,
248
    clkA   => bus_clk,
249
    pulseA => start,
250
    clkB   => core_clk,
251
    pulseB => core_start
252
  );
253
 
254
  -- go from core clock domain to bus clock domain
255
  ready_pulse : pulse_cdc
256
  port map(
257
    reset  => reset,
258
    clkA   => core_clk,
259
    pulseA => core_ready,
260
    clkB   => bus_clk,
261
    pulseB => ready
262
  );
263
 
264
  sync_to_bus_clk : clk_sync
265
  port map(
266
    sigA => core_calc_time,
267
    clkB => bus_clk,
268
    sigB => calc_time
269
  );
270
 
271
  collision_pulse : pulse_cdc
272
  port map(
273
    reset  => reset,
274
    clkA   => core_clk,
275
    pulseA => core_collision,
276
    clkB   => bus_clk,
277
    pulseB => collision
278
  );
279 2 JonasDC
 
280 24 JonasDC
end Structural;

powered by: WebSVN 2.1.0

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