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

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

Line No. Rev Author Line
1 25 JonasDC
----------------------------------------------------------------------  
2
----  sys_pipeline                                                ---- 
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
----    the pipelined systolic array for a montgommery multiplier ----
10
----                                                              ----
11
----  Dependencies:                                               ----
12
----    - sys_stage                                               ----
13
----    - register_n                                              ----
14
----    - d_flip_flop                                             ----
15
----    - cell_1b_adder                                           ----
16
----    - cell_1b_mux                                             ----
17
----                                                              ----
18
----  Authors:                                                    ----
19
----      - Geoffrey Ottoy, DraMCo research group                 ----
20
----      - Jonas De Craene, JonasDC@opencores.org                ---- 
21
----                                                              ---- 
22
---------------------------------------------------------------------- 
23
----                                                              ---- 
24
---- Copyright (C) 2011 DraMCo research group and OPENCORES.ORG   ---- 
25
----                                                              ---- 
26
---- This source file may be used and distributed without         ---- 
27
---- restriction provided that this copyright statement is not    ---- 
28
---- removed from the file and that any derivative work contains  ---- 
29
---- the original copyright notice and the associated disclaimer. ---- 
30
----                                                              ---- 
31
---- This source file is free software; you can redistribute it   ---- 
32
---- and/or modify it under the terms of the GNU Lesser General   ---- 
33
---- Public License as published by the Free Software Foundation; ---- 
34
---- either version 2.1 of the License, or (at your option) any   ---- 
35
---- later version.                                               ---- 
36
----                                                              ---- 
37
---- This source is distributed in the hope that it will be       ---- 
38
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ---- 
39
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ---- 
40
---- PURPOSE.  See the GNU Lesser General Public License for more ---- 
41
---- details.                                                     ---- 
42
----                                                              ---- 
43
---- You should have received a copy of the GNU Lesser General    ---- 
44
---- Public License along with this source; if not, download it   ---- 
45
---- from http://www.opencores.org/lgpl.shtml                     ---- 
46
----                                                              ---- 
47
----------------------------------------------------------------------
48
 
49
library ieee;
50
use ieee.std_logic_1164.all;
51
use ieee.std_logic_unsigned.all;
52
 
53
library mod_sim_exp;
54
use mod_sim_exp.mod_sim_exp_pkg.all;
55
 
56
-- the pipelined systolic array for a montgommery multiplier
57
-- contains a structural description of the pipeline using the systolic stages
58
entity sys_pipeline is
59
        generic(
60
    n  : integer := 1536; -- width of the operands (# bits)
61
    t  : integer := 192;  -- total number of stages (divider of n) >= 2
62
    tl : integer := 64    -- lower number of stages (best take t = sqrt(n))
63
  );
64
  port(
65
    -- clock input
66
    core_clk : in  std_logic;
67
    -- modulus and y opperand input (n)-bit
68
    y        : in  std_logic_vector((n-1) downto 0);
69
    m        : in  std_logic_vector((n-1) downto 0);
70
    -- x operand input (serial)
71
    xi       : in  std_logic;
72
    next_x   : out std_logic; -- next x operand bit
73
    -- control signals
74
    start    : in  std_logic; -- start multiplier
75
    reset    : in  std_logic;
76
    p_sel    : in  std_logic_vector(1 downto 0); -- select which piece of the pipeline will be used
77
    -- result out
78
    r        : out std_logic_vector((n-1) downto 0)
79
  );
80
end sys_pipeline;
81
 
82
architecture Structural of sys_pipeline is
83
  constant s : integer := n/t;
84
 
85
 
86
  signal m_i           : std_logic_vector(n downto 0);
87
  signal y_i           : std_logic_vector(n downto 0);
88 36 JonasDC
  signal r_sel_l : std_logic;
89
  signal r_sel_h : std_logic;
90 25 JonasDC
 
91
  -- systolic stages signals
92
  signal my_cin_stage  : std_logic_vector((t-1) downto 0);
93
  signal my_cout_stage : std_logic_vector((t-1) downto 0);
94
  signal xin_stage     : std_logic_vector((t-1) downto 0);
95
  signal qin_stage     : std_logic_vector((t-1) downto 0);
96
  signal xout_stage    : std_logic_vector((t-1) downto 0);
97
  signal qout_stage    : std_logic_vector((t-1) downto 0);
98
  signal a_msb_stage   : std_logic_vector((t-1) downto 0);
99
  signal a_0_stage     : std_logic_vector((t-1) downto 0);
100
  signal cin_stage     : std_logic_vector((t-1) downto 0);
101
  signal cout_stage    : std_logic_vector((t-1) downto 0);
102
  signal red_cin_stage : std_logic_vector((t-1) downto 0);
103
  signal red_cout_stage : std_logic_vector((t-1) downto 0);
104
  signal start_stage   : std_logic_vector((t-1) downto 0);
105
  signal done_stage    : std_logic_vector((t-1) downto 0);
106 36 JonasDC
  signal r_sel_stage   : std_logic_vector((t-1) downto 0);
107 25 JonasDC
 
108 32 JonasDC
  -- mid end signals
109
  signal a_0_midend : std_logic;
110
  signal r_sel_midend : std_logic;
111 25 JonasDC
 
112 32 JonasDC
  -- mid start signals
113
  signal my_cout_midstart : std_logic;
114
  signal xout_midstart : std_logic;
115
  signal qout_midstart : std_logic;
116
  signal cout_midstart : std_logic;
117
  signal red_cout_midstart : std_logic;
118
 
119
  -- end signals
120
  signal r_sel_end : std_logic;
121 25 JonasDC
begin
122
 
123
  m_i <= '0' & m;
124
  y_i <= '0' & y;
125
 
126
  -- generate the stages for the full pipeline
127
  pipeline_stages : for i in 0 to (t-1) generate
128
    stage : sys_stage
129
    generic map(
130
      width => s
131
    )
132
    port map(
133
      core_clk => core_clk,
134
      y        => y_i((i+1)*s downto (i*s)+1),
135
      m        => m_i((i+1)*s downto (i*s)),
136
      my_cin   => my_cin_stage(i),
137
      my_cout  => my_cout_stage(i),
138
      xin      => xin_stage(i),
139
      qin      => qin_stage(i),
140
      xout     => xout_stage(i),
141
      qout     => qout_stage(i),
142
      a_0      => a_0_stage(i),
143
      a_msb    => a_msb_stage(i),
144
      cin      => cin_stage(i),
145
      cout     => cout_stage(i),
146
      red_cin  => red_cin_stage(i),
147
      red_cout => red_cout_stage(i),
148
      start    => start_stage(i),
149
      reset    => reset,
150
      done     => done_stage(i),
151 36 JonasDC
      r_sel    => r_sel_stage(i),
152 25 JonasDC
      r        => r(((i+1)*s)-1 downto (i*s))
153
    );
154
  end generate;
155
 
156
  -- first cell logic
157
  --------------------
158 32 JonasDC
  first_cell : sys_first_cell_logic
159 31 JonasDC
  port map (
160
    m0       => m_i(0),
161
    y0       => y_i(0),
162
    my_cout  => my_cin_stage(0),
163
    xi       => xi,
164
    xout     => xin_stage(0),
165
    qout     => qin_stage(0),
166
    cout     => cin_stage(0),
167
    a_0      => a_0_stage(0),
168
    red_cout => red_cin_stage(0)
169 25 JonasDC
  );
170
 
171 32 JonasDC
  -- only start first stage if lower part is used
172
  with p_sel select
173
    start_stage(0) <= '0' when "10",
174
                      start when others;
175 25 JonasDC
 
176 32 JonasDC
  with p_sel select
177
    next_x <= done_stage(tl) when "10",
178
              done_stage(0) when others;
179
 
180
  -- link lower stages to eachother
181
  stage_connect_l : for i in 1 to (tl-1) generate
182
    my_cin_stage(i) <= my_cout_stage(i-1);
183
    cin_stage(i) <= cout_stage(i-1);
184
    xin_stage(i) <= xout_stage(i-1);
185
    qin_stage(i) <= qout_stage(i-1);
186
    red_cin_stage(i) <= red_cout_stage(i-1);
187
    start_stage(i) <= done_stage(i-1);
188
    a_msb_stage(i-1) <= a_0_stage(i);
189 36 JonasDC
    r_sel_stage(i) <= r_sel_l;
190 32 JonasDC
  end generate;
191 36 JonasDC
    r_sel_stage(0) <= r_sel_l;
192 32 JonasDC
 
193
  -- mid end logic
194
  -----------------
195
  mid_end_cell : sys_last_cell_logic
196
  port map (
197
    core_clk => core_clk,
198
    reset    => reset,
199
    a_0      => a_0_midend,
200
    cin      => cout_stage(tl-1),
201
    red_cin  => red_cout_stage(tl-1),
202
    r_sel    => r_sel_midend,
203
    start    => done_stage(tl-1)
204
  );
205
  --muxes for midend signals
206
  with p_sel select
207
    a_msb_stage(tl-1) <= a_0_midend when "01",
208
                         a_0_stage(tl) when others;
209
 
210
  -- mid start logic
211
  -------------------
212
  mid_start_logic : sys_first_cell_logic
213
  port map (
214
    m0       => m_i(tl*s),
215
    y0       => y_i(tl*s),
216
    my_cout  => my_cout_midstart,
217
    xi       => xi,
218
    xout     => xout_midstart,
219
    qout     => qout_midstart,
220
    cout     => cout_midstart,
221
    a_0      => a_0_stage(tl),
222
    red_cout => red_cout_midstart
223
  );
224
 
225
  -- only start stage tl if only higher part is used
226
  with p_sel select
227
    start_stage(tl) <= start when "10",
228
                       done_stage(tl-1) when "11",
229
                       '0' when others;
230
 
231
  with p_sel select
232
    my_cin_stage(tl) <= my_cout_midstart when "10",
233
                        my_cout_stage(tl-1) when others;
234
  with p_sel select
235
    xin_stage(tl) <= xout_midstart when "10",
236
                     xout_stage(tl-1) when others;
237
  with p_sel select
238
    qin_stage(tl) <= qout_midstart when "10",
239
                     qout_stage(tl-1) when others;
240
  with p_sel select
241
    cin_stage(tl) <= cout_midstart when "10",
242
                     cout_stage(tl-1) when others;
243
  with p_sel select
244
    red_cin_stage(tl) <= red_cout_midstart when "10",
245
                         red_cout_stage(tl-1) when others;
246
 
247
    -- link higher stages to eachother
248
  stage_connect_h : for i in (tl+1) to (t-1) generate
249
    my_cin_stage(i) <= my_cout_stage(i-1);
250
    cin_stage(i) <= cout_stage(i-1);
251
    xin_stage(i) <= xout_stage(i-1);
252
    qin_stage(i) <= qout_stage(i-1);
253
    red_cin_stage(i) <= red_cout_stage(i-1);
254
    start_stage(i) <= done_stage(i-1);
255
    a_msb_stage(i-1) <= a_0_stage(i);
256 36 JonasDC
    r_sel_stage(i) <= r_sel_h;
257 32 JonasDC
  end generate;
258 36 JonasDC
    r_sel_stage(tl) <= r_sel_h;
259
 
260 25 JonasDC
  -- last cell logic
261
  -------------------
262 30 JonasDC
  last_cell : sys_last_cell_logic
263
  port map (
264 25 JonasDC
    core_clk => core_clk,
265
    reset    => reset,
266 30 JonasDC
    a_0      => a_msb_stage(t-1),
267
    cin      => cout_stage(t-1),
268
    red_cin  => red_cout_stage(t-1),
269 32 JonasDC
    r_sel    => r_sel_end,
270 30 JonasDC
    start    => done_stage(t-1)
271 25 JonasDC
  );
272
 
273 32 JonasDC
  with p_sel select
274 36 JonasDC
    r_sel_l <= r_sel_midend when "01",
275
               r_sel_end when "11",
276
               '0' when others;
277
 
278
  with p_sel select
279
    r_sel_h <= '0' when "01",
280
               r_sel_end when others;
281
 
282 25 JonasDC
end Structural;

powered by: WebSVN 2.1.0

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