1 |
3 |
JonasDC |
----------------------------------------------------------------------
|
2 |
|
|
---- autorun_ctrl ----
|
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 |
|
|
---- autorun control unit for a pipelined montgomery ----
|
10 |
|
|
---- multiplier ----
|
11 |
|
|
---- ----
|
12 |
|
|
---- Dependencies: none ----
|
13 |
|
|
---- ----
|
14 |
|
|
---- Authors: ----
|
15 |
|
|
---- - Geoffrey Ottoy, DraMCo research group ----
|
16 |
|
|
---- - Jonas De Craene, JonasDC@opencores.org ----
|
17 |
|
|
---- ----
|
18 |
|
|
----------------------------------------------------------------------
|
19 |
|
|
---- ----
|
20 |
|
|
---- Copyright (C) 2011 DraMCo research group and OPENCORES.ORG ----
|
21 |
|
|
---- ----
|
22 |
|
|
---- This source file may be used and distributed without ----
|
23 |
|
|
---- restriction provided that this copyright statement is not ----
|
24 |
|
|
---- removed from the file and that any derivative work contains ----
|
25 |
|
|
---- the original copyright notice and the associated disclaimer. ----
|
26 |
|
|
---- ----
|
27 |
|
|
---- This source file is free software; you can redistribute it ----
|
28 |
|
|
---- and/or modify it under the terms of the GNU Lesser General ----
|
29 |
|
|
---- Public License as published by the Free Software Foundation; ----
|
30 |
|
|
---- either version 2.1 of the License, or (at your option) any ----
|
31 |
|
|
---- later version. ----
|
32 |
|
|
---- ----
|
33 |
|
|
---- This source is distributed in the hope that it will be ----
|
34 |
|
|
---- useful, but WITHOUT ANY WARRANTY; without even the implied ----
|
35 |
|
|
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----
|
36 |
|
|
---- PURPOSE. See the GNU Lesser General Public License for more ----
|
37 |
|
|
---- details. ----
|
38 |
|
|
---- ----
|
39 |
|
|
---- You should have received a copy of the GNU Lesser General ----
|
40 |
|
|
---- Public License along with this source; if not, download it ----
|
41 |
|
|
---- from http://www.opencores.org/lgpl.shtml ----
|
42 |
|
|
---- ----
|
43 |
|
|
----------------------------------------------------------------------
|
44 |
2 |
JonasDC |
|
45 |
3 |
JonasDC |
library ieee;
|
46 |
|
|
use ieee.std_logic_1164.all;
|
47 |
|
|
use ieee.std_logic_arith.all;
|
48 |
|
|
use ieee.std_logic_unsigned.all;
|
49 |
2 |
JonasDC |
|
50 |
3 |
JonasDC |
|
51 |
2 |
JonasDC |
entity autorun_cntrl is
|
52 |
3 |
JonasDC |
port (
|
53 |
|
|
clk : in std_logic;
|
54 |
|
|
reset : in std_logic;
|
55 |
|
|
start : in std_logic;
|
56 |
|
|
done : out std_logic;
|
57 |
|
|
op_sel : out std_logic_vector (1 downto 0);
|
58 |
|
|
start_multiplier : out std_logic;
|
59 |
|
|
multiplier_done : in std_logic;
|
60 |
|
|
read_buffer : out std_logic;
|
61 |
|
|
buffer_din : in std_logic_vector (31 downto 0);
|
62 |
|
|
buffer_empty : in std_logic
|
63 |
|
|
);
|
64 |
2 |
JonasDC |
end autorun_cntrl;
|
65 |
|
|
|
66 |
3 |
JonasDC |
|
67 |
2 |
JonasDC |
architecture Behavioral of autorun_cntrl is
|
68 |
|
|
|
69 |
3 |
JonasDC |
signal bit_counter_i : integer range 0 to 15 := 0;
|
70 |
|
|
signal bit_counter_0_i : std_logic;
|
71 |
|
|
signal bit_counter_15_i : std_logic;
|
72 |
|
|
signal next_bit_i : std_logic := '0';
|
73 |
|
|
|
74 |
|
|
signal start_cycle_i : std_logic := '0';
|
75 |
|
|
signal start_cycle_del_i : std_logic;
|
76 |
|
|
|
77 |
|
|
signal done_i : std_logic;
|
78 |
|
|
signal running_i : std_logic;
|
79 |
|
|
|
80 |
|
|
signal start_multiplier_i : std_logic;
|
81 |
|
|
signal start_multiplier_del_i : std_logic;
|
82 |
|
|
signal mult_done_del_i : std_logic;
|
83 |
|
|
|
84 |
|
|
signal e0_i : std_logic_vector(15 downto 0);
|
85 |
|
|
signal e1_i : std_logic_vector(15 downto 0);
|
86 |
|
|
signal e0_bit_i : std_logic;
|
87 |
|
|
signal e1_bit_i : std_logic;
|
88 |
|
|
signal e_bits_i : std_logic_vector(1 downto 0);
|
89 |
|
|
signal e_bits_0_i : std_logic;
|
90 |
|
|
signal cycle_counter_i : std_logic;
|
91 |
|
|
signal op_sel_sel_i : std_logic;
|
92 |
|
|
signal op_sel_i : std_logic_vector(1 downto 0);
|
93 |
|
|
begin
|
94 |
2 |
JonasDC |
|
95 |
|
|
done <= done_i;
|
96 |
|
|
|
97 |
|
|
-- the two exponents
|
98 |
|
|
e0_i <= buffer_din(15 downto 0);
|
99 |
|
|
e1_i <= buffer_din(31 downto 16);
|
100 |
|
|
|
101 |
|
|
-- generate the index to select a single bit from the two exponents
|
102 |
|
|
SYNC_BIT_COUNTER: process (clk, reset)
|
103 |
|
|
begin
|
104 |
|
|
if reset = '1' then
|
105 |
|
|
bit_counter_i <= 15;
|
106 |
|
|
elsif rising_edge(clk) then
|
107 |
|
|
if start = '1' then -- make sure we start @ bit 0
|
108 |
|
|
bit_counter_i <= 15;
|
109 |
|
|
elsif next_bit_i = '1' then -- count
|
110 |
|
|
if bit_counter_i = 0 then
|
111 |
|
|
bit_counter_i <= 15;
|
112 |
|
|
else
|
113 |
|
|
bit_counter_i <= bit_counter_i - 1;
|
114 |
|
|
end if;
|
115 |
|
|
end if;
|
116 |
|
|
end if;
|
117 |
|
|
end process SYNC_BIT_COUNTER;
|
118 |
|
|
-- signal when bit_counter_i = 0
|
119 |
|
|
bit_counter_0_i <= '1' when bit_counter_i=0 else '0';
|
120 |
|
|
bit_counter_15_i <= '1' when bit_counter_i=15 else '0';
|
121 |
|
|
-- the bits...
|
122 |
|
|
e0_bit_i <= e0_i(bit_counter_i);
|
123 |
|
|
e1_bit_i <= e1_i(bit_counter_i);
|
124 |
|
|
e_bits_i <= e0_bit_i & e1_bit_i;
|
125 |
|
|
e_bits_0_i <= '1' when (e_bits_i = "00") else '0';
|
126 |
|
|
|
127 |
|
|
-- operand pre-select
|
128 |
|
|
with e_bits_i select
|
129 |
|
|
op_sel_i <= "00" when "10", -- gt0
|
130 |
|
|
"01" when "01", -- gt1
|
131 |
|
|
"10" when "11", -- gt01
|
132 |
|
|
"11" when others;
|
133 |
|
|
|
134 |
|
|
-- select operands
|
135 |
|
|
op_sel_sel_i <= '0' when e_bits_0_i = '1' else (cycle_counter_i);
|
136 |
|
|
op_sel <= op_sel_i when op_sel_sel_i = '1' else "11";
|
137 |
|
|
|
138 |
|
|
-- process that drives running_i signal ('1' when in autorun, '0' when not)
|
139 |
|
|
RUNNING_PROC: process(clk, reset)
|
140 |
|
|
begin
|
141 |
|
|
if reset = '1' then
|
142 |
|
|
running_i <= '0';
|
143 |
|
|
elsif rising_edge(clk) then
|
144 |
|
|
running_i <= start or (running_i and (not done_i));
|
145 |
|
|
end if;
|
146 |
|
|
end process RUNNING_PROC;
|
147 |
|
|
|
148 |
|
|
-- ctrl logic
|
149 |
|
|
start_multiplier_i <= start_cycle_del_i or (mult_done_del_i and (cycle_counter_i) and (not e_bits_0_i));
|
150 |
|
|
read_buffer <= start_cycle_del_i and bit_counter_15_i and running_i; -- pop new word from fifo when bit_counter is back at '15'
|
151 |
|
|
start_multiplier <= start_multiplier_del_i and running_i;
|
152 |
|
|
|
153 |
|
|
-- start/stop logic
|
154 |
|
|
start_cycle_i <= (start and (not buffer_empty)) or next_bit_i; -- start pulse (external or internal)
|
155 |
|
|
done_i <= (start and buffer_empty) or (next_bit_i and bit_counter_0_i and buffer_empty); -- stop when buffer is empty
|
156 |
|
|
next_bit_i <= (mult_done_del_i and e_bits_0_i) or (mult_done_del_i and (not e_bits_0_i) and (not cycle_counter_i));
|
157 |
|
|
|
158 |
|
|
-- process for delaying signals with 1 clock cycle
|
159 |
|
|
DEL_PROC: process(clk)
|
160 |
|
|
begin
|
161 |
|
|
if rising_edge(clk) then
|
162 |
|
|
start_multiplier_del_i <= start_multiplier_i;
|
163 |
|
|
start_cycle_del_i <= start_cycle_i;
|
164 |
|
|
mult_done_del_i <= multiplier_done;
|
165 |
|
|
end if;
|
166 |
|
|
end process DEL_PROC;
|
167 |
|
|
|
168 |
|
|
-- process for delaying signals with 1 clock cycle
|
169 |
39 |
JonasDC |
CYCLE_CNTR_PROC: process(clk, start, reset)
|
170 |
2 |
JonasDC |
begin
|
171 |
|
|
if start = '1' or reset = '1' then
|
172 |
|
|
cycle_counter_i <= '0';
|
173 |
|
|
elsif rising_edge(clk) then
|
174 |
|
|
if (e_bits_0_i = '0') and (multiplier_done = '1') then
|
175 |
|
|
cycle_counter_i <= not cycle_counter_i;
|
176 |
|
|
elsif (e_bits_0_i = '1') and (multiplier_done = '1') then
|
177 |
|
|
cycle_counter_i <= '0';
|
178 |
|
|
else
|
179 |
|
|
cycle_counter_i <= cycle_counter_i;
|
180 |
|
|
end if;
|
181 |
|
|
end if;
|
182 |
|
|
end process CYCLE_CNTR_PROC;
|
183 |
|
|
|
184 |
|
|
end Behavioral;
|
185 |
|
|
|