1 |
2 |
JonasDC |
------------------------------------------------------------------------------------
|
2 |
|
|
--
|
3 |
|
|
-- Geoffrey Ottoy - DraMCo research group
|
4 |
|
|
--
|
5 |
|
|
-- Module Name: multiplier_core.vhd / entity multiplier_core
|
6 |
|
|
--
|
7 |
|
|
-- Last Modified: 18/06/2012
|
8 |
|
|
--
|
9 |
|
|
-- Description: a pipelined montgomery multiplier, with split
|
10 |
|
|
-- pipeline operation and "auto-run" support
|
11 |
|
|
--
|
12 |
|
|
--
|
13 |
|
|
-- Dependencies: mont_mult_sys_pipeline, operand_mem, fifo_primitive, mont_cntrl
|
14 |
|
|
--
|
15 |
|
|
-- Revision:
|
16 |
|
|
-- Revision 6.00 - created seperate module for x-operand (x_shift_reg)
|
17 |
|
|
-- Revision 5.00 - moved fifo interface to shared memory
|
18 |
|
|
-- Revision 4.00 - added dest_op_single input
|
19 |
|
|
-- Revision 3.00 - added auto-run control
|
20 |
|
|
-- Revision 2.01 - Split ctrl_reg input to separate inputs with more descriptive
|
21 |
|
|
-- names
|
22 |
|
|
-- Revision 2.00 - Control logic moved to separate design module and added fifo
|
23 |
|
|
-- Revision 1.00 - Architecture based on multiplier IP core "mont_mult1536_v1_00_a"
|
24 |
|
|
-- Revision 0.01 - File Created
|
25 |
|
|
--
|
26 |
|
|
--
|
27 |
|
|
------------------------------------------------------------------------------------
|
28 |
|
|
--
|
29 |
|
|
-- NOTICE:
|
30 |
|
|
--
|
31 |
|
|
-- Copyright DraMCo research group. 2011. This code may be contain portions patented
|
32 |
|
|
-- by other third parties!
|
33 |
|
|
--
|
34 |
|
|
------------------------------------------------------------------------------------
|
35 |
|
|
library IEEE;
|
36 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
37 |
|
|
use IEEE.STD_LOGIC_ARITH.ALL;
|
38 |
|
|
use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
39 |
|
|
|
40 |
|
|
---- Uncomment the following library declaration if instantiating
|
41 |
|
|
---- any Xilinx primitives in this code.
|
42 |
|
|
--library UNISIM;
|
43 |
|
|
--use UNISIM.VComponents.all;
|
44 |
|
|
|
45 |
|
|
entity multiplier_core is
|
46 |
|
|
port( clk : in std_logic;
|
47 |
|
|
reset : in std_logic;
|
48 |
|
|
-- operand memory interface (plb shared memory)
|
49 |
|
|
write_enable : in std_logic;
|
50 |
|
|
data_in : in std_logic_vector (31 downto 0);
|
51 |
|
|
rw_address : in std_logic_vector (8 downto 0);
|
52 |
|
|
data_out : out std_logic_vector (31 downto 0);
|
53 |
|
|
collision : out std_logic;
|
54 |
|
|
-- op_sel fifo interface
|
55 |
|
|
fifo_din : in std_logic_vector (31 downto 0);
|
56 |
|
|
fifo_push : in std_logic;
|
57 |
|
|
fifo_full : out std_logic;
|
58 |
|
|
fifo_nopush : out std_logic;
|
59 |
|
|
-- ctrl signals
|
60 |
|
|
start : in std_logic;
|
61 |
|
|
run_auto : in std_logic;
|
62 |
|
|
ready : out std_logic;
|
63 |
|
|
x_sel_single : in std_logic_vector (1 downto 0);
|
64 |
|
|
y_sel_single : in std_logic_vector (1 downto 0);
|
65 |
|
|
dest_op_single : in std_logic_vector (1 downto 0);
|
66 |
|
|
p_sel : in std_logic_vector (1 downto 0);
|
67 |
|
|
calc_time : out std_logic
|
68 |
|
|
);
|
69 |
|
|
end multiplier_core;
|
70 |
|
|
|
71 |
|
|
architecture Behavioral of multiplier_core is
|
72 |
|
|
component mont_mult_sys_pipeline
|
73 |
|
|
generic ( n : integer := 32;
|
74 |
|
|
nr_stages : integer := 8; --(divides n, bits_low & (n-bits_low))
|
75 |
|
|
stages_low : integer := 3
|
76 |
|
|
);
|
77 |
|
|
Port ( core_clk : in STD_LOGIC;
|
78 |
|
|
xy : in STD_LOGIC_VECTOR((n-1) downto 0);
|
79 |
|
|
m : in STD_LOGIC_VECTOR((n-1) downto 0);
|
80 |
|
|
r : out STD_LOGIC_VECTOR((n-1) downto 0);
|
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 component;
|
88 |
|
|
|
89 |
|
|
component operand_mem
|
90 |
|
|
port(
|
91 |
|
|
data_in : in std_logic_vector(31 downto 0);
|
92 |
|
|
data_out : out std_logic_vector(31 downto 0);
|
93 |
|
|
rw_address : in std_logic_vector(8 downto 0);
|
94 |
|
|
op_sel : in std_logic_vector(1 downto 0);
|
95 |
|
|
xy_out : out std_logic_vector(1535 downto 0);
|
96 |
|
|
m : out std_logic_vector(1535 downto 0);
|
97 |
|
|
result_in : in std_logic_vector(1535 downto 0);
|
98 |
|
|
load_op : in std_logic;
|
99 |
|
|
load_m : in std_logic;
|
100 |
|
|
load_result : in std_logic;
|
101 |
|
|
result_dest_op : in std_logic_vector(1 downto 0);
|
102 |
|
|
collision : out std_logic;
|
103 |
|
|
clk : in std_logic
|
104 |
|
|
);
|
105 |
|
|
end component;
|
106 |
|
|
|
107 |
|
|
component fifo_primitive
|
108 |
|
|
port(
|
109 |
|
|
clk : in std_logic;
|
110 |
|
|
din : in std_logic_vector(31 downto 0);
|
111 |
|
|
push : in std_logic;
|
112 |
|
|
pop : in std_logic;
|
113 |
|
|
reset : in std_logic;
|
114 |
|
|
dout : out std_logic_vector(31 downto 0);
|
115 |
|
|
empty : out std_logic;
|
116 |
|
|
full : out std_logic;
|
117 |
|
|
nopop : out std_logic;
|
118 |
|
|
nopush : out std_logic
|
119 |
|
|
);
|
120 |
|
|
end component;
|
121 |
|
|
|
122 |
|
|
component mont_ctrl
|
123 |
|
|
port(
|
124 |
|
|
clk : in std_logic;
|
125 |
|
|
reset : in std_logic;
|
126 |
|
|
start : in std_logic;
|
127 |
|
|
x_sel_single : in std_logic_vector(1 downto 0);
|
128 |
|
|
y_sel_single : in std_logic_vector(1 downto 0);
|
129 |
|
|
run_auto : in std_logic;
|
130 |
|
|
op_sel_buffer : in std_logic_vector(31 downto 0);
|
131 |
|
|
read_buffer : out std_logic;
|
132 |
|
|
multiplier_ready : in std_logic;
|
133 |
|
|
op_buffer_empty : in std_logic;
|
134 |
|
|
buffer_noread : in std_logic;
|
135 |
|
|
done : out std_logic;
|
136 |
|
|
calc_time : out std_logic;
|
137 |
|
|
op_sel : out std_logic_vector(1 downto 0);
|
138 |
|
|
load_x : out std_logic;
|
139 |
|
|
load_result : out std_logic;
|
140 |
|
|
start_multiplier : out std_logic
|
141 |
|
|
);
|
142 |
|
|
end component;
|
143 |
|
|
|
144 |
|
|
signal xy_i : std_logic_vector(1535 downto 0);
|
145 |
|
|
signal x_i : std_logic;
|
146 |
|
|
signal m : std_logic_vector(1535 downto 0);
|
147 |
|
|
signal r : std_logic_vector(1535 downto 0);
|
148 |
|
|
|
149 |
|
|
signal op_sel : std_logic_vector(1 downto 0);
|
150 |
|
|
signal result_dest_op_i : std_logic_vector(1 downto 0);
|
151 |
|
|
signal mult_ready : std_logic;
|
152 |
|
|
signal start_mult : std_logic;
|
153 |
|
|
signal load_op : std_logic;
|
154 |
|
|
signal load_x_i : std_logic;
|
155 |
|
|
signal load_m : std_logic;
|
156 |
|
|
signal load_result : std_logic;
|
157 |
|
|
|
158 |
|
|
signal fifo_empty : std_logic;
|
159 |
|
|
signal fifo_pop : std_logic;
|
160 |
|
|
signal fifo_nopop : std_logic;
|
161 |
|
|
signal fifo_dout : std_logic_vector(31 downto 0);
|
162 |
|
|
--signal fifo_push : std_logic;
|
163 |
|
|
|
164 |
|
|
constant n : integer := 1536;
|
165 |
|
|
constant t : integer := 96;
|
166 |
|
|
constant tl : integer := 32;
|
167 |
|
|
begin
|
168 |
|
|
|
169 |
|
|
-- The actual multiplier
|
170 |
|
|
the_multiplier: mont_mult_sys_pipeline generic map(
|
171 |
|
|
n => n,
|
172 |
|
|
nr_stages => t, --(divides n, bits_low & (n-bits_low))
|
173 |
|
|
stages_low => tl
|
174 |
|
|
)
|
175 |
|
|
port map(
|
176 |
|
|
core_clk => clk,
|
177 |
|
|
xy => xy_i,
|
178 |
|
|
m => m,
|
179 |
|
|
r => r,
|
180 |
|
|
start => start_mult,
|
181 |
|
|
reset => reset,
|
182 |
|
|
p_sel => p_sel,
|
183 |
|
|
load_x => load_x_i,
|
184 |
|
|
ready => mult_ready
|
185 |
|
|
);
|
186 |
|
|
|
187 |
|
|
-- Block ram memory for storing the operands and the modulus
|
188 |
|
|
the_memory: operand_mem port map(
|
189 |
|
|
data_in => data_in,
|
190 |
|
|
data_out => data_out,
|
191 |
|
|
rw_address => rw_address,
|
192 |
|
|
op_sel => op_sel,
|
193 |
|
|
xy_out => xy_i,
|
194 |
|
|
m => m,
|
195 |
|
|
result_in => r,
|
196 |
|
|
load_op => load_op,
|
197 |
|
|
load_m => load_m,
|
198 |
|
|
load_result => load_result,
|
199 |
|
|
result_dest_op => result_dest_op_i,
|
200 |
|
|
collision => collision,
|
201 |
|
|
clk => clk
|
202 |
|
|
);
|
203 |
|
|
load_op <= write_enable when (rw_address(8) = '0') else '0';
|
204 |
|
|
load_m <= write_enable when (rw_address(8) = '1') else '0';
|
205 |
|
|
result_dest_op_i <= dest_op_single when run_auto = '0' else "11"; -- in autorun mode we always store the result in operand3
|
206 |
|
|
|
207 |
|
|
-- A fifo for auto-run operand selection
|
208 |
|
|
the_exponent_fifo: fifo_primitive port map(
|
209 |
|
|
clk => clk,
|
210 |
|
|
din => fifo_din,
|
211 |
|
|
dout => fifo_dout,
|
212 |
|
|
empty => fifo_empty,
|
213 |
|
|
full => fifo_full,
|
214 |
|
|
push => fifo_push,
|
215 |
|
|
pop => fifo_pop,
|
216 |
|
|
reset => reset,
|
217 |
|
|
nopop => fifo_nopop,
|
218 |
|
|
nopush => fifo_nopush
|
219 |
|
|
);
|
220 |
|
|
|
221 |
|
|
-- The control logic for the core
|
222 |
|
|
the_control_unit: mont_ctrl port map(
|
223 |
|
|
clk => clk,
|
224 |
|
|
reset => reset,
|
225 |
|
|
start => start,
|
226 |
|
|
x_sel_single => x_sel_single,
|
227 |
|
|
y_sel_single => y_sel_single,
|
228 |
|
|
run_auto => run_auto,
|
229 |
|
|
op_buffer_empty => fifo_empty,
|
230 |
|
|
op_sel_buffer => fifo_dout,
|
231 |
|
|
read_buffer => fifo_pop,
|
232 |
|
|
buffer_noread => fifo_nopop,
|
233 |
|
|
done => ready,
|
234 |
|
|
calc_time => calc_time,
|
235 |
|
|
op_sel => op_sel,
|
236 |
|
|
load_x => load_x_i,
|
237 |
|
|
load_result => load_result,
|
238 |
|
|
start_multiplier => start_mult,
|
239 |
|
|
multiplier_ready => mult_ready
|
240 |
|
|
);
|
241 |
|
|
|
242 |
|
|
|
243 |
|
|
end Behavioral;
|
244 |
|
|
|