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/] [mont_multiplier.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
----  mont_multiplier                                             ---- 
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
----    n-bit montgomery multiplier with a pipelined systolic     ----
10
----    array                                                     ----
11
----                                                              ----
12
----  Dependencies:                                               ----
13
----    - x_shift_reg                                             ----
14
----    - adder_n                                                 ----
15
----    - d_flip_flop                                             ----
16
----    - sys_pipeline                                            ----
17
----    - cell_1b_adder                                           ----
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
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
-- Structural description of the montgommery multiply pipeline
57
-- contains the x operand shift register, my adder, the pipeline and 
58
-- reduction adder. To do a multiplication, the following actions must take place:
59
-- 
60
--    * load in the x operand in the shift register using the xy bus and load_x
61
--    * place the y operand on the xy bus for the rest of the operation
62
--    * generate a start pulse of 1 clk cycle long on start
63
--    * wait for ready signal
64
--    * result is avaiable on the r bus
65
-- 
66
entity mont_multiplier is
67
  generic (
68
    n          : integer := 1536; -- width of the operands
69
    nr_stages  : integer := 96; -- total number of stages
70
    stages_low : integer := 32  -- lower number of stages
71
  );
72
  port (
73
    -- clock input
74
    core_clk : in std_logic;
75
    -- operand inputs
76
    xy       : in std_logic_vector((n-1) downto 0); -- bus for x or y operand
77
    m        : in std_logic_vector((n-1) downto 0); -- modulus
78
    -- result output
79
    r        : out std_logic_vector((n-1) downto 0);  -- result
80
    -- control signals
81
    start    : in std_logic;
82
    reset    : in std_logic;
83
    p_sel    : in std_logic_vector(1 downto 0);
84
    load_x   : in std_logic;
85
    ready    : out std_logic
86
  );
87
end mont_multiplier;
88
 
89
architecture Structural of mont_multiplier is
90
  constant s  : integer := n/nr_stages;   -- stage width (# bits)
91
 
92
  signal reset_multiplier : std_logic;
93
  signal start_multiplier : std_logic;
94
 
95
  signal next_xi : std_logic;
96
  signal xi : std_logic;
97
 
98
  signal start_first_stage : std_logic;
99
 
100
begin
101
 
102
  -- multiplier is reset every calculation or reset
103
  reset_multiplier <= reset or start;
104
 
105
  -- start is delayed 1 cycle
106
  delay_1_cycle : d_flip_flop
107
  port map(
108
    core_clk => core_clk,
109
    reset    => reset,
110
    din      => start,
111
    dout     => start_multiplier
112
  );
113
 
114
  -- register to store the x value in 
115
  -- outputs the operand in serial using a shift register 
116
  x_selection : x_shift_reg
117
  generic map(
118
    n  => n,
119
    t  => nr_stages,
120
    tl => stages_low
121
  )
122
  port map(
123
    clk    => core_clk,
124
    reset  => reset,
125
    x_in   => xy,
126
    load_x => load_x,
127
    next_x => next_xi,
128
    p_sel  => p_sel,
129
    xi     => xi
130
  );
131
 
132
  -- stepping control logic to keep track off the multiplication and when it is done
133
  stepping_control : stepping_logic
134
  generic map(
135
    n => n, -- max nr of steps required to complete a multiplication
136
    t => nr_stages -- total nr of steps in the pipeline
137
  )
138
  port map(
139
    core_clk          => core_clk,
140
    start             => start_multiplier,
141
    reset             => reset_multiplier,
142
    t_sel             => nr_stages,
143
    n_sel             => n-1,
144
    start_first_stage => start_first_stage,
145
    stepping_done     => ready
146
  );
147
 
148
  systolic_array : sys_pipeline
149
  generic map(
150
    n  => n,
151
    t  => nr_stages,
152
    tl => stages_low
153
  )
154
  port map(
155
    core_clk => core_clk,
156
    y       => xy,
157
    m       => m,
158
    xi      => xi,
159
    next_x  => next_xi,
160
    start   => start_first_stage,
161
    reset   => reset_multiplier,
162
    p_sel   => p_sel,
163
    r       => r
164
  );
165
 
166
end Structural;
167
 

powered by: WebSVN 2.1.0

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