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 89

Go to most recent revision | 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 69 JonasDC
    C_FIFO_DEPTH      : integer := 32;
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 89 JonasDC
    core_clk : in  std_logic;
74
    reset    : in  std_logic;
75 3 JonasDC
      -- operand memory interface (plb shared memory)
76 89 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 89 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 89 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 89 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 89 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 89 JonasDC
--  xil_prim_fifo : if C_MEM_STYLE="xil_prim" generate
167 69 JonasDC
    the_exponent_fifo : fifo_primitive
168
    port map(
169 89 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 89 JonasDC
--  end generate;
182
--  gen_fifo : if (C_MEM_STYLE="generic") or (C_MEM_STYLE="asym") generate
183
--    the_exponent_fifo : fifo_generic
184
--    generic map(
185
--      depth => C_FIFO_DEPTH
186
--    )
187
--    port map(
188
--      clk    => bus_clk,
189
--      din    => fifo_din,
190
--      dout   => fifo_dout,
191
--      empty  => fifo_empty,
192
--      full   => fifo_full,
193
--      push   => fifo_push,
194
--      pop    => fifo_pop,
195
--      reset  => reset,
196
--      nopop  => fifo_nopop,
197
--      nopush => fifo_nopush
198
--    );
199
--  end generate;
200 69 JonasDC
 
201 89 JonasDC
  -- The actual multiplier
202
  the_multiplier : mont_multiplier
203
  generic map(
204
    n     => C_NR_BITS_TOTAL,
205
    t     => C_NR_STAGES_TOTAL,
206
    tl    => C_NR_STAGES_LOW,
207
    split => C_SPLIT_PIPELINE
208
  )
209
  port map(
210
    core_clk => core_clk,
211
    xy       => xy,
212
    m        => m,
213
    r        => r,
214
    start    => start_mult,
215
    reset    => reset,  -- asynchronious reset
216
    p_sel    => p_sel,
217
    load_x   => load_x,
218
    ready    => mult_ready
219
  );
220
 
221 3 JonasDC
  -- The control logic for the core
222 24 JonasDC
  the_control_unit : mont_ctrl
223
  port map(
224 89 JonasDC
    clk              => core_clk,
225
    reset            => reset, -- asynchronious reset
226
    start            => core_start,
227 3 JonasDC
    x_sel_single     => x_sel_single,
228
    y_sel_single     => y_sel_single,
229 45 JonasDC
    run_auto         => exp_m,
230 3 JonasDC
    op_buffer_empty  => fifo_empty,
231
    op_sel_buffer    => fifo_dout,
232
    read_buffer      => fifo_pop,
233 89 JonasDC
    done             => core_ready,
234
    calc_time        => core_calc_time,
235 3 JonasDC
    op_sel           => op_sel,
236 24 JonasDC
    load_x           => load_x,
237 3 JonasDC
    load_result      => load_result,
238
    start_multiplier => start_mult,
239
    multiplier_ready => mult_ready
240
  );
241 89 JonasDC
 
242
  -- go from bus clock domain to core clock domain
243
  start_pulse : pulse_cdc
244
  port map(
245
    reset  => reset,
246
    clkA   => bus_clk,
247
    pulseA => start,
248
    clkB   => core_clk,
249
    pulseB => core_start
250
  );
251
 
252
  -- go from core clock domain to bus clock domain
253
  ready_pulse : pulse_cdc
254
  port map(
255
    reset  => reset,
256
    clkA   => core_clk,
257
    pulseA => core_ready,
258
    clkB   => bus_clk,
259
    pulseB => ready
260
  );
261
 
262
  sync_to_bus_clk : clk_sync
263
  port map(
264
    sigA => core_calc_time,
265
    clkB => bus_clk,
266
    sigB => calc_time
267
  );
268
 
269
  collision_pulse : pulse_cdc
270
  port map(
271
    reset  => reset,
272
    clkA   => core_clk,
273
    pulseA => core_collision,
274
    clkB   => bus_clk,
275
    pulseB => collision
276
  );
277 2 JonasDC
 
278 24 JonasDC
end Structural;

powered by: WebSVN 2.1.0

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