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

Subversion Repositories mod_sim_exp

[/] [mod_sim_exp/] [tags/] [Release_1.0/] [rtl/] [vhdl/] [core/] [first_stage.vhd] - Blame information for rev 100

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 JonasDC
----------------------------------------------------------------------  
2
----  first_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
----    first stage for use in the montgommery multiplier         ----
10
----    systolic array pipeline                                   ----
11
----                                                              ----
12
----  Dependencies:                                               ----
13
----    - standard_cell_block                                     ----
14
----    - d_flip_flop                                             ----
15
----    - register_n                                              ----
16
----    - register_1b                                             ----
17
----    - cell_1b_mux                                             ----
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 2 JonasDC
 
50 3 JonasDC
library ieee;
51
use ieee.std_logic_1164.all;
52
use ieee.std_logic_arith.all;
53
use ieee.std_logic_unsigned.all;
54 2 JonasDC
 
55 3 JonasDC
library mod_sim_exp;
56
use mod_sim_exp.mod_sim_exp_pkg.all;
57
 
58 18 JonasDC
-- first stage for use in the montgommery multiplier pipeline
59
-- generates the q signal for all following stages
60
-- the result is available after 1 clock cycle
61 2 JonasDC
entity first_stage is
62 3 JonasDC
  generic(
63
    width : integer := 16 -- must be the same as width of the standard stage
64
  );
65
  port(
66 18 JonasDC
    -- clock input
67 3 JonasDC
    core_clk : in  std_logic;
68 18 JonasDC
    -- modulus and y operand input (width+1)-bit
69 3 JonasDC
    my       : in  std_logic_vector((width) downto 0);
70
    y        : in  std_logic_vector((width) downto 0);
71
    m        : in  std_logic_vector((width) downto 0);
72 18 JonasDC
    -- x operand input (serial input)
73 3 JonasDC
    xin      : in  std_logic;
74 18 JonasDC
    -- q and x operand output (serial output)
75 3 JonasDC
    xout     : out std_logic;
76
    qout     : out std_logic;
77 18 JonasDC
    -- msb input (lsb from next stage, for shift right operation)
78 3 JonasDC
    a_msb    : in  std_logic;
79 18 JonasDC
    -- carry out
80 3 JonasDC
    cout     : out std_logic;
81 18 JonasDC
    -- control signals
82 3 JonasDC
    start    : in  std_logic;
83
    reset    : in  std_logic;
84
    done     : out std_logic;
85 18 JonasDC
    -- result out
86 3 JonasDC
    r        : out std_logic_vector((width-1) downto 0)
87
  );
88 2 JonasDC
end first_stage;
89
 
90 3 JonasDC
 
91 2 JonasDC
architecture Structural of first_stage is
92 3 JonasDC
  -- output
93
  signal cout_i     : std_logic;
94
  signal r_i        : std_logic_vector((width-1) downto 0);
95 18 JonasDC
  signal r_i_reg    : std_logic_vector((width-1) downto 0);
96
  signal qout_i      : std_logic;
97 2 JonasDC
 
98 3 JonasDC
  -- interconnection
99 18 JonasDC
  signal first_res   : std_logic;
100
  signal c_first_res : std_logic;
101
  signal a           : std_logic_vector((width) downto 0);
102 2 JonasDC
 
103
begin
104
 
105
        -- map internal signals to outputs
106 18 JonasDC
        r <= r_i_reg;
107 2 JonasDC
 
108 18 JonasDC
        -- a is equal to the right shifted version(/2) of r_reg with a_msb as MSB
109
        a <= a_msb & r_i_reg;
110 2 JonasDC
 
111 18 JonasDC
        -- compute first q and carry
112
        qout_i <= a(0) xor (y(0) and xin);
113
        c_first_res <= a(0) and first_res;
114 2 JonasDC
 
115 3 JonasDC
  first_cell : cell_1b_mux
116
  port map(
117
    my     => my(0),
118
    y      => y(0),
119
    m      => m(0),
120 18 JonasDC
    x      => xin,
121
    q      => qout_i,
122
    result => first_res
123 3 JonasDC
  );
124
 
125 18 JonasDC
  -- structure of (width) standard_cell_blocks
126 3 JonasDC
  cell_block : standard_cell_block
127
  generic map(
128
    width => width
129
  )
130
  port map(
131
    my   => my(width downto 1),
132
    y    => y(width downto 1),
133
    m    => m(width downto 1),
134 18 JonasDC
    x    => xin,
135
    q    => qout_i,
136
    a    => a(width downto 1),
137
    cin  => c_first_res,
138 3 JonasDC
    cout => cout_i,
139
    r    => r_i((width-1) downto 0)
140
  );
141
 
142 18 JonasDC
  -- stage done signal
143
  -- 1 cycle after start of stage
144 3 JonasDC
  done_signal : d_flip_flop
145
  port map(
146
    core_clk => core_clk,
147
    reset    => reset,
148
    din      => start,
149 18 JonasDC
    dout     => done
150 3 JonasDC
  );
151
 
152
  -- output registers
153 18 JonasDC
  --------------------
154
 
155
  -- result register (width)-bit
156
  result_reg : register_n
157 3 JonasDC
  generic map(
158 15 JonasDC
    width => width
159 3 JonasDC
  )
160
  port map(
161
    core_clk => core_clk,
162
    ce       => start,
163
    reset    => reset,
164
    din      => r_i,
165 18 JonasDC
    dout     => r_i_reg
166 3 JonasDC
  );
167
 
168 18 JonasDC
  -- xout register
169
  xout_reg : register_1b
170 3 JonasDC
  port map(
171
    core_clk => core_clk,
172
    ce       => start,
173
    reset    => reset,
174 18 JonasDC
    din      => xin,
175
    dout     => xout
176 3 JonasDC
  );
177 18 JonasDC
 
178
  -- qout register
179
  qout_reg : register_1b
180 3 JonasDC
  port map(
181
    core_clk => core_clk,
182
    ce       => start,
183
    reset    => reset,
184 18 JonasDC
    din      => qout_i,
185
    dout     => qout
186 3 JonasDC
  );
187
 
188 18 JonasDC
  -- carry out register
189
  cout_reg : register_1b
190 3 JonasDC
  port map(
191
    core_clk => core_clk,
192
    ce       => start,
193
    reset    => reset,
194
    din      => cout_i,
195 18 JonasDC
    dout     => cout
196 3 JonasDC
  );
197
 
198 18 JonasDC
end Structural;

powered by: WebSVN 2.1.0

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