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_stage.vhd] - Blame information for rev 41

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

Line No. Rev Author Line
1 25 JonasDC
----------------------------------------------------------------------  
2
----  sys_stage                                                   ---- 
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
----    stage for use in the montgommery multiplier pipelined     ----
10
----    systolic array                                            ----
11
----                                                              ----
12
----  Dependencies:                                               ----
13
----    - adder_block                                             ----
14
----    - standard_cell_block                                     ----
15
----    - d_flip_flop                                             ----
16
----    - register_n                                              ----
17
----    - register_1b                                             ----
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
 
50
library ieee;
51
use ieee.std_logic_1164.all;
52
use ieee.std_logic_unsigned.all;
53
 
54
library mod_sim_exp;
55
use mod_sim_exp.mod_sim_exp_pkg.all;
56
 
57
entity sys_stage is
58
  generic(
59
    width : integer := 32 -- width of the stage
60
  );
61
  port(
62
    -- clock input
63
    core_clk : in  std_logic;
64
    -- modulus and y operand input (width)-bit
65
    y        : in  std_logic_vector((width-1) downto 0);
66
    m        : in  std_logic_vector((width) downto 0);
67
    my_cin   : in  std_logic;
68
    my_cout  : out std_logic;
69
    -- q and x operand input (serial input)
70
    xin      : in  std_logic;
71
    qin      : in  std_logic;
72
    -- q and x operand output (serial output)
73
    xout     : out std_logic;
74
    qout     : out std_logic;
75
    -- msb input (lsb from next stage, for shift right operation)
76
    a_msb    : in  std_logic;
77
    a_0      : out std_logic;
78
    -- carry out(clocked) and in
79
    cin      : in  std_logic;
80
    cout     : out std_logic;
81
    -- reduction adder carry's
82
    red_cin  : in std_logic;
83
    red_cout : out std_logic;
84
    -- control singals
85
    start    : in  std_logic;
86
    reset    : in  std_logic;
87
    done     : out std_logic;
88
    -- result out
89
    r_sel    : in  std_logic; -- result selection: 0 -> pipeline result, 1 -> reducted result
90
    r        : out std_logic_vector((width-1) downto 0)
91
  );
92
end sys_stage;
93
 
94
architecture Structural of sys_stage is
95
  signal my : std_logic_vector((width-1) downto 0);
96
  signal m_inv : std_logic_vector((width-1) downto 0);
97
  signal a : std_logic_vector((width-1) downto 0);
98
  signal cell_result : std_logic_vector((width-1) downto 0);
99
  signal cell_result_reg : std_logic_vector((width-1) downto 0);
100
  signal red_r : std_logic_vector((width-1) downto 0);
101
 
102
  signal cout_i : std_logic;
103
 
104
begin
105
 
106
  -- my adder
107
  ------------
108
  my_adder : adder_block
109
  generic map (
110
    width => width
111
  )
112
  port map(
113
    core_clk => core_clk,
114
    a => m(width downto 1),
115
    b => y,
116
    cin => my_cin,
117
    cout => my_cout,
118
    r => my
119
  );
120
 
121
 
122
  -- systolic pipeline cells
123
  ---------------------------
124
  a <= a_msb & cell_result_reg((width-1) downto 1);
125
  a_0 <= cell_result_reg(0);
126
  sys_cells : standard_cell_block
127
  generic map (
128
    width => width
129
  )
130
  port map (
131
    -- modulus and y operand input (width)-bit
132
    my => my,
133
    y => y,
134
    m => m(width downto 1),
135
    -- q and x operand input (serial input)
136
    x => xin,
137
    q => qin,
138
    -- previous result in (width)-bit
139
    a => a,
140
    -- carry in and out
141
    cin => cin,
142
    cout => cout_i,
143
    -- result out (width)-bit
144
    r => cell_result
145
  );
146
 
147
  -- cell result register (width)-bit
148
  result_reg : register_n
149
  generic map(
150
    width => width
151
  )
152
  port map(
153
    core_clk => core_clk,
154
    ce    => start,
155
    reset => reset,
156
    din   => cell_result,
157
    dout  => cell_result_reg
158
  );
159
 
160
 
161
  -- result reduction
162
  --------------------
163
  m_inv <= not(m(width-1 downto 0));
164
 
165
  reduction_adder : adder_block
166
  generic map (
167
    width => width
168
  )
169
  port map(
170
    core_clk => core_clk,
171
    a => m_inv,
172
    b => cell_result_reg,
173
    cin => red_cin,
174
    cout => red_cout,
175
    r => red_r
176
  );
177
 
178
  with r_sel select
179
    r <= cell_result_reg when '0',
180
                   red_r when others;
181
 
182
 
183
  -- stage clocked outputs
184
  -------------------------
185
  -- stage done signal
186
  -- 1 cycle after start of stage
187
  done_signal : d_flip_flop
188
  port map(
189
    core_clk  => core_clk,
190
    reset => reset,
191
    din   => start,
192
    dout  => done
193
  );
194
 
195
  -- xout register
196
  xout_reg : register_1b
197
  port map(
198
    core_clk => core_clk,
199
    ce    => start,
200
    reset => reset,
201
    din   => xin,
202
    dout  => xout
203
  );
204
 
205
  -- qout register
206
  qout_reg : register_1b
207
  port map(
208
    core_clk => core_clk,
209
    ce    => start,
210
    reset => reset,
211
    din   => qin,
212
    dout  => qout
213
  );
214
 
215
  -- carry out register
216
  cout_reg : register_1b
217
  port map(
218
    core_clk => core_clk,
219
    ce    => start,
220
    reset => reset,
221
    din   => cout_i,
222
    dout  => cout
223
  );
224
 
225
end Structural;
226
 

powered by: WebSVN 2.1.0

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