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 25

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
  -- first cell signals
107
  signal my0_mux_result : std_logic;
108
  signal my0 : std_logic;
109
 
110
  -- last cell signals
111
  signal a_high : std_logic_vector(1 downto 0);
112
  signal a_high_reg : std_logic_vector(1 downto 0);
113
  signal red_cout_end : std_logic_vector(1 downto 0);
114
 
115
 
116
begin
117
 
118
  m_i <= '0' & m;
119
  y_i <= '0' & y;
120
 
121
  -- generate the stages for the full pipeline
122
  pipeline_stages : for i in 0 to (t-1) generate
123
    stage : sys_stage
124
    generic map(
125
      width => s
126
    )
127
    port map(
128
      core_clk => core_clk,
129
      y        => y_i((i+1)*s downto (i*s)+1),
130
      m        => m_i((i+1)*s downto (i*s)),
131
      my_cin   => my_cin_stage(i),
132
      my_cout  => my_cout_stage(i),
133
      xin      => xin_stage(i),
134
      qin      => qin_stage(i),
135
      xout     => xout_stage(i),
136
      qout     => qout_stage(i),
137
      a_0      => a_0_stage(i),
138
      a_msb    => a_msb_stage(i),
139
      cin      => cin_stage(i),
140
      cout     => cout_stage(i),
141
      red_cin  => red_cin_stage(i),
142
      red_cout => red_cout_stage(i),
143
      start    => start_stage(i),
144
      reset    => reset,
145
      done     => done_stage(i),
146
      r_sel    => r_sel,
147
      r        => r(((i+1)*s)-1 downto (i*s))
148
    );
149
  end generate;
150
 
151
  -- link stages to eachother
152
  stage_connect : for i in 1 to (t-1) generate
153
    my_cin_stage(i) <= my_cout_stage(i-1);
154
    cin_stage(i) <= cout_stage(i-1);
155
    xin_stage(i) <= xout_stage(i-1);
156
    qin_stage(i) <= qout_stage(i-1);
157
    red_cin_stage(i) <= red_cout_stage(i-1);
158
    start_stage(i) <= done_stage(i-1);
159
    a_msb_stage(i-1) <= a_0_stage(i);
160
  end generate;
161
 
162
  -- first cell logic
163
  --------------------
164
  my0 <= m_i(0) xor y_i(0); -- m0 + y0
165
  -- stage 0 connections
166
  my_cin_stage(0) <= m_i(0) and y_i(0); -- m0 + y0 carry
167
  xin_stage(0) <= xi;
168
  qin_stage(0) <= (xi and y_i(0)) xor a_0_stage(0);
169
  cin_stage(0) <= my0_mux_result and a_0_stage(0);
170
  red_cin_stage(0) <= '1'; -- add 1 for 2s complement
171
  start_stage(0) <= start;
172
 
173
  my0_mux : cell_1b_mux
174
  port map(
175
    my     => my0,
176
    m      => m_i(0),
177
    y      => y_i(0),
178
    x      => xin_stage(0),
179
    q      => qin_stage(0),
180
    result => my0_mux_result
181
  );
182
 
183
  next_x <= done_stage(0);
184
 
185
  -- last cell logic
186
  -------------------
187
  -- half adder: cout_stage(t-1) + a_high_reg(1)
188
  a_high(0) <= cout_stage(t-1) xor a_high_reg(1); --result
189
  a_high(1) <= cout_stage(t-1) and a_high_reg(1); --cout
190
 
191
  a_msb_stage(t-1) <= a_high_reg(0);
192
 
193
  last_reg : register_n
194
  generic map(
195
    width => 2
196
  )
197
  port map(
198
    core_clk => core_clk,
199
    ce       => done_stage(t-1),
200
    reset    => reset,
201
    din      => a_high,
202
    dout     => a_high_reg
203
  );
204
 
205
  -- reduction finishing last 2 bits
206
  reduction_adder_a : cell_1b_adder
207
  port map(
208
    a     => '1', -- for 2s complement of m
209
    b     => a_high_reg(0),
210
    cin   => red_cout_stage(t-1),
211
    cout  => red_cout_end(0)
212
  );
213
 
214
  reduction_adder_b : cell_1b_adder
215
  port map(
216
    a     => '1', -- for 2s complement of m
217
    b     => a_high_reg(1),
218
    cin   => red_cout_end(0),
219
    cout  => red_cout_end(1)
220
  );
221
 
222
  r_sel <= red_cout_end(1);
223
 
224
end Structural;

powered by: WebSVN 2.1.0

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