OpenCores
URL https://opencores.org/ocsvn/mod_sim_exp/mod_sim_exp/trunk

Subversion Repositories mod_sim_exp

[/] [mod_sim_exp/] [tags/] [start_version/] [rtl/] [vhdl/] [core/] [mont_mult_sys_pipeline.vhd] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 JonasDC
------------------------------------------------------------------------------------ 
2
--                      
3
-- Geoffrey Ottoy - DraMCo research group
4
--
5
-- Module Name: mont_mult_sys_pipeline.vhd / entity mont_mult_sys_pipeline
6
-- 
7
-- Last Modified:       18/06/2012 
8
-- 
9
-- Description:         n-bit montgomery multiplier with a pipelined systolic array
10
--
11
--
12
-- Dependencies:        systolic_pipeline
13
--                                              adder_n
14
--                                              cell_1b_adder
15
--                x_shift_register
16
--
17
-- Revision:
18
-- Revision 3.00 - shift register for x selection in stead of decoding logic
19
-- Revision 2.01 - Bug fix of the bug fix
20
-- Revision 2.00 - Major bug fix in reduction logic (carry in upper part)
21
--      Revision 1.00 - Architecture
22
--      Revision 0.01 - File Created
23
--
24
--
25
------------------------------------------------------------------------------------
26
--
27
-- NOTICE:
28
--
29
-- Copyright DraMCo research group. 2011. This code may be contain portions patented
30
-- by other third parties!
31
--
32
------------------------------------------------------------------------------------
33
library IEEE;
34
use IEEE.STD_LOGIC_1164.ALL;
35
use IEEE.STD_LOGIC_ARITH.ALL;
36
use IEEE.STD_LOGIC_UNSIGNED.ALL;
37
 
38
---- Uncomment the following library declaration if instantiating
39
---- any Xilinx primitives in this code.
40
--library UNISIM;
41
--use UNISIM.VComponents.all;
42
 
43
entity mont_mult_sys_pipeline is
44
        generic ( n : integer := 1536;
45
                nr_stages : integer := 96; --(divides n, bits_low & (n-bits_low))
46
                stages_low : integer := 32
47
        );
48
   Port ( core_clk : in STD_LOGIC;
49
           xy : in  STD_LOGIC_VECTOR((n-1) downto 0);
50
           m : in  STD_LOGIC_VECTOR((n-1) downto 0);
51
           r : out  STD_LOGIC_VECTOR((n-1) downto 0);
52
                          start : in STD_LOGIC;
53
                          reset : in STD_LOGIC;
54
                          p_sel : in  STD_LOGIC_VECTOR(1 downto 0);
55
                          load_x : in std_logic;
56
                          ready : out STD_LOGIC
57
        );
58
end mont_mult_sys_pipeline;
59
 
60
architecture Structural of mont_mult_sys_pipeline is
61
        component adder_n
62
        generic ( width : integer := 16;
63
                block_width : integer := 4
64
        );
65
   Port ( core_clk : in STD_LOGIC;
66
                          a : in  STD_LOGIC_VECTOR((width-1) downto 0);
67
           b : in  STD_LOGIC_VECTOR((width-1) downto 0);
68
                          cin : in STD_LOGIC;
69
                          cout : out STD_LOGIC;
70
           s : out  STD_LOGIC_VECTOR((width-1) downto 0)
71
        );
72
        end component;
73
 
74
        component systolic_pipeline
75
        generic( n : integer := 1536; -- width of the operands (# bits)
76
                                t : integer := 96;  -- number of stages (divider of n) >= 2
77
                                tl: integer := 32
78
        );
79
   port(core_clk : in  STD_LOGIC;
80
                             my : in  STD_LOGIC_VECTOR((n) downto 0);
81
               y : in  STD_LOGIC_VECTOR((n-1) downto 0);
82
               m : in  STD_LOGIC_VECTOR((n-1) downto 0);
83
              xi : in  STD_LOGIC;
84
                          start : in  STD_LOGIC;
85
                          reset : in  STD_LOGIC;
86
                          p_sel : in  STD_LOGIC_VECTOR(1 downto 0);
87
                          ready : out STD_LOGIC;
88
                         next_x : out STD_LOGIC;
89
               r : out STD_LOGIC_VECTOR((n+1) downto 0)
90
        );
91
        end component;
92
 
93
        component x_shift_reg
94
        generic(  n : integer := 32;
95
                       t : integer := 8;
96
                                tl : integer := 3
97
        );
98
        port(   clk : in  STD_LOGIC;
99
         reset : in  STD_LOGIC;
100
          x_in : in  STD_LOGIC_VECTOR((n-1) downto 0);
101
        load_x : in  STD_LOGIC;
102
        next_x : in  STD_LOGIC;
103
                   p_sel : in  STD_LOGIC_VECTOR(1 downto 0);
104
           x_i : out STD_LOGIC
105
        );
106
        end component;
107
 
108
        component cell_1b_adder
109
                 Port ( a : in  STD_LOGIC;
110
                                  mux_result : in  STD_LOGIC;
111
                                  cin : in  STD_LOGIC;
112
                                  cout : out  STD_LOGIC;
113
                                  r : out  STD_LOGIC);
114
        end component;
115
 
116
        component d_flip_flop
117
   port(core_clk : in  STD_LOGIC;
118
                          reset : in  STD_LOGIC;
119
                            din : in  STD_LOGIC;
120
                      dout : out STD_LOGIC
121
        );
122
        end component;
123
 
124
        constant stage_width : integer := n/nr_stages;
125
        constant bits_l : integer := stage_width * stages_low;
126
        constant bits_h : integer := n - bits_l;
127
 
128
        signal my : std_logic_vector(n downto 0);
129
        signal my_h_cin : std_logic;
130
        signal my_l_cout : std_logic;
131
        signal r_pipeline : std_logic_vector(n+1 downto 0);
132
        signal r_red : std_logic_vector(n-1 downto 0);
133
        signal r_i : std_logic_vector(n-1 downto 0);
134
        signal c_red_l : std_logic_vector(2 downto 0);
135
        signal c_red_h : std_logic_vector(2 downto 0);
136
        signal cin_red_h : std_logic;
137
        signal r_sel : std_logic;
138
        signal reset_multiplier : std_logic;
139
        signal start_multiplier : std_logic;
140
        signal m_inv : std_logic_vector(n-1 downto 0);
141
 
142
        signal next_x_i : std_logic;
143
        signal x_i : std_logic;
144
begin
145
        -- x selection
146
        x_selection: x_shift_reg
147
        generic map(  n => n,
148
                       t => nr_stages,
149
                      tl => stages_low
150
        )
151
        port map(clk => core_clk,
152
         reset => reset,
153
          x_in => xy,
154
        load_x => load_x,
155
        next_x => next_x_i,
156
                   p_sel => p_sel,
157
           x_i => x_i
158
        );
159
 
160
        -- precomputation of my (m+y)
161
        my_adder_l: adder_n
162
        generic map( width => bits_l,
163
                block_width => stage_width
164
        )
165
   port map( core_clk => core_clk,
166
                          a => m((bits_l-1) downto 0),
167
           b => xy((bits_l-1) downto 0),
168
                          cin => '0',
169
                          cout => my_l_cout,
170
           s => my((bits_l-1) downto 0)
171
        );
172
 
173
        my_adder_h: adder_n
174
        generic map( width => bits_h,
175
                block_width => stage_width
176
        )
177
   port map( core_clk => core_clk,
178
                          a => m((n-1) downto bits_l),
179
           b => xy((n-1) downto bits_l),
180
                          cin => my_h_cin,
181
                          cout => my(n),
182
           s => my((n-1) downto bits_l)
183
        );
184
 
185
        my_h_cin <= '0' when (p_sel(1) and (not p_sel(0)))='1' else my_l_cout;
186
 
187
        -- multiplication       
188
        reset_multiplier <= reset or start;
189
 
190
        delay_1_cycle: d_flip_flop
191
   port map(core_clk => core_clk,
192
                          reset => reset,
193
                            din => start,
194
                      dout => start_multiplier
195
        );
196
 
197
 
198
        the_multiplier: systolic_pipeline
199
        generic map( n => n, -- width of the operands (# bits)
200
                                t => nr_stages,  -- number of stages (divider of n) >= 2
201
                                tl => stages_low
202
        )
203
   port map(core_clk => core_clk,
204
                             my => my,
205
               y => xy,
206
               m => m,
207
              xi => x_i,
208
                          start => start_multiplier,
209
                          reset => reset_multiplier,
210
                          p_sel => p_sel,
211
                          ready => ready, -- misschien net iets te vroeg?
212
                         next_x => next_x_i,
213
               r => r_pipeline
214
        );
215
 
216
        -- post-computation (reduction)
217
        m_inv <= not(m);
218
 
219
        reduction_adder_l: adder_n
220
        generic map( width => bits_l,
221
                block_width => stage_width
222
        )
223
   port map( core_clk => core_clk,
224
                          a => m_inv((bits_l-1) downto 0),
225
           b => r_pipeline((bits_l-1) downto 0),
226
                          cin => '1',
227
                          cout => c_red_l(0),
228
           s => r_red((bits_l-1) downto 0)
229
        );
230
 
231
        reduction_adder_l_a: cell_1b_adder
232
        port map(a => '1',
233
                                mux_result => r_pipeline(bits_l),
234
                                cin => c_red_l(0),
235
                                cout => c_red_l(1)
236
                                --r => 
237
        );
238
 
239
        reduction_adder_l_b: cell_1b_adder
240
        port map(a => '1',
241
                                mux_result => r_pipeline(bits_l+1),
242
                                cin => c_red_l(1),
243
                                cout => c_red_l(2)
244
        --                      r => 
245
        );
246
 
247
        --cin_red_h <= p_sel(1) and (not p_sel(0));
248
        cin_red_h <= c_red_l(0) when p_sel(0) = '1' else '1';
249
 
250
        reduction_adder_h: adder_n
251
        generic map( width => bits_h,
252
                block_width => stage_width
253
        )
254
   port map( core_clk => core_clk,
255
                          a => m_inv((n-1) downto bits_l),
256
           b => r_pipeline((n-1) downto bits_l),
257
                          cin => cin_red_h,
258
                          cout => c_red_h(0),
259
           s => r_red((n-1) downto bits_l)
260
        );
261
 
262
        reduction_adder_h_a: cell_1b_adder
263
        port map(a => '1',
264
                                mux_result => r_pipeline(n),
265
                                cin => c_red_h(0),
266
                                cout => c_red_h(1)
267
        );
268
 
269
        reduction_adder_h_b: cell_1b_adder
270
        port map(a => '1',
271
                                mux_result => r_pipeline(n+1),
272
                                cin => c_red_h(1),
273
                                cout => c_red_h(2)
274
        );
275
 
276
        r_sel <= (c_red_h(2) and p_sel(1)) or (c_red_l(2) and (p_sel(0) and (not p_sel(1))));
277
        r_i <= r_red when r_sel = '1' else r_pipeline((n-1) downto 0);
278
 
279
        -- output
280
        r <= r_i;
281
end Structural;

powered by: WebSVN 2.1.0

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