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 32

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
 
89
  -- systolic stages signals
90
  signal my_cin_stage  : std_logic_vector((t-1) downto 0);
91
  signal my_cout_stage : std_logic_vector((t-1) downto 0);
92
  signal xin_stage     : std_logic_vector((t-1) downto 0);
93
  signal qin_stage     : std_logic_vector((t-1) downto 0);
94
  signal xout_stage    : std_logic_vector((t-1) downto 0);
95
  signal qout_stage    : std_logic_vector((t-1) downto 0);
96
  signal a_msb_stage   : std_logic_vector((t-1) downto 0);
97
  signal a_0_stage     : std_logic_vector((t-1) downto 0);
98
  signal cin_stage     : std_logic_vector((t-1) downto 0);
99
  signal cout_stage    : std_logic_vector((t-1) downto 0);
100
  signal red_cin_stage : std_logic_vector((t-1) downto 0);
101
  signal red_cout_stage : std_logic_vector((t-1) downto 0);
102
  signal start_stage   : std_logic_vector((t-1) downto 0);
103
  signal done_stage    : std_logic_vector((t-1) downto 0);
104
  signal r_sel         : std_logic;
105
 
106 32 JonasDC
  -- mid end signals
107
  signal a_0_midend : std_logic;
108
  signal r_sel_midend : std_logic;
109 25 JonasDC
 
110 32 JonasDC
  -- mid start signals
111
  signal my_cout_midstart : std_logic;
112
  signal xout_midstart : std_logic;
113
  signal qout_midstart : std_logic;
114
  signal cout_midstart : std_logic;
115
  signal red_cout_midstart : std_logic;
116
 
117
  -- end signals
118
  signal r_sel_end : std_logic;
119 25 JonasDC
begin
120
 
121
  m_i <= '0' & m;
122
  y_i <= '0' & y;
123
 
124
  -- generate the stages for the full pipeline
125
  pipeline_stages : for i in 0 to (t-1) generate
126
    stage : sys_stage
127
    generic map(
128
      width => s
129
    )
130
    port map(
131
      core_clk => core_clk,
132
      y        => y_i((i+1)*s downto (i*s)+1),
133
      m        => m_i((i+1)*s downto (i*s)),
134
      my_cin   => my_cin_stage(i),
135
      my_cout  => my_cout_stage(i),
136
      xin      => xin_stage(i),
137
      qin      => qin_stage(i),
138
      xout     => xout_stage(i),
139
      qout     => qout_stage(i),
140
      a_0      => a_0_stage(i),
141
      a_msb    => a_msb_stage(i),
142
      cin      => cin_stage(i),
143
      cout     => cout_stage(i),
144
      red_cin  => red_cin_stage(i),
145
      red_cout => red_cout_stage(i),
146
      start    => start_stage(i),
147
      reset    => reset,
148
      done     => done_stage(i),
149
      r_sel    => r_sel,
150
      r        => r(((i+1)*s)-1 downto (i*s))
151
    );
152
  end generate;
153
 
154
 
155 32 JonasDC
 
156 25 JonasDC
  -- 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
  end generate;
190
 
191
  -- mid end logic
192
  -----------------
193
  mid_end_cell : sys_last_cell_logic
194
  port map (
195
    core_clk => core_clk,
196
    reset    => reset,
197
    a_0      => a_0_midend,
198
    cin      => cout_stage(tl-1),
199
    red_cin  => red_cout_stage(tl-1),
200
    r_sel    => r_sel_midend,
201
    start    => done_stage(tl-1)
202
  );
203
  --muxes for midend signals
204
  with p_sel select
205
    a_msb_stage(tl-1) <= a_0_midend when "01",
206
                         a_0_stage(tl) when others;
207
 
208
  -- mid start logic
209
  -------------------
210
  mid_start_logic : sys_first_cell_logic
211
  port map (
212
    m0       => m_i(tl*s),
213
    y0       => y_i(tl*s),
214
    my_cout  => my_cout_midstart,
215
    xi       => xi,
216
    xout     => xout_midstart,
217
    qout     => qout_midstart,
218
    cout     => cout_midstart,
219
    a_0      => a_0_stage(tl),
220
    red_cout => red_cout_midstart
221
  );
222
 
223
  -- only start stage tl if only higher part is used
224
  with p_sel select
225
    start_stage(tl) <= start when "10",
226
                       done_stage(tl-1) when "11",
227
                       '0' when others;
228
 
229
  with p_sel select
230
    my_cin_stage(tl) <= my_cout_midstart when "10",
231
                        my_cout_stage(tl-1) when others;
232
  with p_sel select
233
    xin_stage(tl) <= xout_midstart when "10",
234
                     xout_stage(tl-1) when others;
235
  with p_sel select
236
    qin_stage(tl) <= qout_midstart when "10",
237
                     qout_stage(tl-1) when others;
238
  with p_sel select
239
    cin_stage(tl) <= cout_midstart when "10",
240
                     cout_stage(tl-1) when others;
241
  with p_sel select
242
    red_cin_stage(tl) <= red_cout_midstart when "10",
243
                         red_cout_stage(tl-1) when others;
244
 
245
    -- link higher stages to eachother
246
  stage_connect_h : for i in (tl+1) to (t-1) generate
247
    my_cin_stage(i) <= my_cout_stage(i-1);
248
    cin_stage(i) <= cout_stage(i-1);
249
    xin_stage(i) <= xout_stage(i-1);
250
    qin_stage(i) <= qout_stage(i-1);
251
    red_cin_stage(i) <= red_cout_stage(i-1);
252
    start_stage(i) <= done_stage(i-1);
253
    a_msb_stage(i-1) <= a_0_stage(i);
254
  end generate;
255
 
256 25 JonasDC
  -- last cell logic
257
  -------------------
258 30 JonasDC
  last_cell : sys_last_cell_logic
259
  port map (
260 25 JonasDC
    core_clk => core_clk,
261
    reset    => reset,
262 30 JonasDC
    a_0      => a_msb_stage(t-1),
263
    cin      => cout_stage(t-1),
264
    red_cin  => red_cout_stage(t-1),
265 32 JonasDC
    r_sel    => r_sel_end,
266 30 JonasDC
    start    => done_stage(t-1)
267 25 JonasDC
  );
268
 
269 32 JonasDC
  with p_sel select
270
    r_sel <= r_sel_midend when "01",
271
             r_sel_end when others;
272 25 JonasDC
end Structural;

powered by: WebSVN 2.1.0

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