1 |
2 |
JonasDC |
------------------------------------------------------------------------------------
|
2 |
|
|
--
|
3 |
|
|
-- Geoffrey Ottoy - DraMCo research group
|
4 |
|
|
--
|
5 |
|
|
-- Module Name: autorun_cntrl.vhd / entity autorun_cntrl
|
6 |
|
|
--
|
7 |
|
|
-- Last Modified: 25/04/2012
|
8 |
|
|
--
|
9 |
|
|
-- Description: autorun control unit for a pipelined montgomery multiplier
|
10 |
|
|
--
|
11 |
|
|
--
|
12 |
|
|
-- Dependencies: none
|
13 |
|
|
--
|
14 |
|
|
-- Revision 2.00 - Major bug fix: bit_counter should count from 15 downto 0.
|
15 |
|
|
-- Revision 1.00 - Architecture created
|
16 |
|
|
-- Revision 0.01 - File Created
|
17 |
|
|
-- Additional Comments:
|
18 |
|
|
--
|
19 |
|
|
--
|
20 |
|
|
------------------------------------------------------------------------------------
|
21 |
|
|
--
|
22 |
|
|
-- NOTICE:
|
23 |
|
|
--
|
24 |
|
|
-- Copyright DraMCo research group. 2011. This code may be contain portions patented
|
25 |
|
|
-- by other third parties!
|
26 |
|
|
--
|
27 |
|
|
----------------------------------------------------------------------------------
|
28 |
|
|
library IEEE;
|
29 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
30 |
|
|
use IEEE.STD_LOGIC_ARITH.ALL;
|
31 |
|
|
use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
32 |
|
|
|
33 |
|
|
---- Uncomment the following library declaration if instantiating
|
34 |
|
|
---- any Xilinx primitives in this code.
|
35 |
|
|
--library UNISIM;
|
36 |
|
|
--use UNISIM.VComponents.all;
|
37 |
|
|
|
38 |
|
|
entity autorun_cntrl is
|
39 |
|
|
Port ( clk : in STD_LOGIC;
|
40 |
|
|
reset : in STD_LOGIC;
|
41 |
|
|
start : in STD_LOGIC;
|
42 |
|
|
done : out STD_LOGIC;
|
43 |
|
|
op_sel : out STD_LOGIC_VECTOR (1 downto 0);
|
44 |
|
|
start_multiplier : out STD_LOGIC;
|
45 |
|
|
multiplier_done : in STD_LOGIC;
|
46 |
|
|
read_buffer : out STD_LOGIC;
|
47 |
|
|
buffer_din : in STD_LOGIC_VECTOR (31 downto 0);
|
48 |
|
|
buffer_empty : in STD_LOGIC);
|
49 |
|
|
end autorun_cntrl;
|
50 |
|
|
|
51 |
|
|
architecture Behavioral of autorun_cntrl is
|
52 |
|
|
|
53 |
|
|
signal bit_counter_i : integer range 0 to 15 := 0;
|
54 |
|
|
signal bit_counter_0_i : std_logic;
|
55 |
|
|
signal bit_counter_15_i : std_logic;
|
56 |
|
|
signal next_bit_i : std_logic := '0';
|
57 |
|
|
signal next_bit_del_i : std_logic;
|
58 |
|
|
|
59 |
|
|
signal start_cycle_i : std_logic := '0';
|
60 |
|
|
signal start_cycle_del_i : std_logic;
|
61 |
|
|
|
62 |
|
|
signal done_i : std_logic;
|
63 |
|
|
signal start_i : std_logic;
|
64 |
|
|
signal running_i : std_logic;
|
65 |
|
|
|
66 |
|
|
signal start_multiplier_i : std_logic;
|
67 |
|
|
signal start_multiplier_del_i : std_logic;
|
68 |
|
|
signal mult_done_del_i : std_logic;
|
69 |
|
|
|
70 |
|
|
signal e0_i : std_logic_vector(15 downto 0);
|
71 |
|
|
signal e1_i : std_logic_vector(15 downto 0);
|
72 |
|
|
signal e0_bit_i : std_logic;
|
73 |
|
|
signal e1_bit_i : std_logic;
|
74 |
|
|
signal e_bits_i : std_logic_vector(1 downto 0);
|
75 |
|
|
signal e_bits_0_i : std_logic;
|
76 |
|
|
signal cycle_counter_i : std_logic;
|
77 |
|
|
signal op_sel_sel_i : std_logic;
|
78 |
|
|
signal op_sel_i : std_logic_vector(1 downto 0);
|
79 |
|
|
begin
|
80 |
|
|
--done <= (multiplier_done and (not running_i)) or (start and buffer_empty);
|
81 |
|
|
done <= done_i;
|
82 |
|
|
|
83 |
|
|
-- the two exponents
|
84 |
|
|
e0_i <= buffer_din(15 downto 0);
|
85 |
|
|
e1_i <= buffer_din(31 downto 16);
|
86 |
|
|
|
87 |
|
|
-- generate the index to select a single bit from the two exponents
|
88 |
|
|
SYNC_BIT_COUNTER: process (clk, reset)
|
89 |
|
|
begin
|
90 |
|
|
if reset = '1' then
|
91 |
|
|
bit_counter_i <= 15;
|
92 |
|
|
elsif rising_edge(clk) then
|
93 |
|
|
if start = '1' then -- make sure we start @ bit 0
|
94 |
|
|
bit_counter_i <= 15;
|
95 |
|
|
elsif next_bit_i = '1' then -- count
|
96 |
|
|
if bit_counter_i = 0 then
|
97 |
|
|
bit_counter_i <= 15;
|
98 |
|
|
else
|
99 |
|
|
bit_counter_i <= bit_counter_i - 1;
|
100 |
|
|
end if;
|
101 |
|
|
end if;
|
102 |
|
|
end if;
|
103 |
|
|
end process SYNC_BIT_COUNTER;
|
104 |
|
|
-- signal when bit_counter_i = 0
|
105 |
|
|
bit_counter_0_i <= '1' when bit_counter_i=0 else '0';
|
106 |
|
|
bit_counter_15_i <= '1' when bit_counter_i=15 else '0';
|
107 |
|
|
-- the bits...
|
108 |
|
|
e0_bit_i <= e0_i(bit_counter_i);
|
109 |
|
|
e1_bit_i <= e1_i(bit_counter_i);
|
110 |
|
|
e_bits_i <= e0_bit_i & e1_bit_i;
|
111 |
|
|
e_bits_0_i <= '1' when (e_bits_i = "00") else '0';
|
112 |
|
|
|
113 |
|
|
-- operand pre-select
|
114 |
|
|
with e_bits_i select
|
115 |
|
|
op_sel_i <= "00" when "10", -- gt0
|
116 |
|
|
"01" when "01", -- gt1
|
117 |
|
|
"10" when "11", -- gt01
|
118 |
|
|
"11" when others;
|
119 |
|
|
|
120 |
|
|
-- select operands
|
121 |
|
|
op_sel_sel_i <= '0' when e_bits_0_i = '1' else (cycle_counter_i);
|
122 |
|
|
op_sel <= op_sel_i when op_sel_sel_i = '1' else "11";
|
123 |
|
|
|
124 |
|
|
-- process that drives running_i signal ('1' when in autorun, '0' when not)
|
125 |
|
|
RUNNING_PROC: process(clk, reset)
|
126 |
|
|
begin
|
127 |
|
|
if reset = '1' then
|
128 |
|
|
running_i <= '0';
|
129 |
|
|
elsif rising_edge(clk) then
|
130 |
|
|
running_i <= start or (running_i and (not done_i));
|
131 |
|
|
end if;
|
132 |
|
|
end process RUNNING_PROC;
|
133 |
|
|
|
134 |
|
|
-- ctrl logic
|
135 |
|
|
start_multiplier_i <= start_cycle_del_i or (mult_done_del_i and (cycle_counter_i) and (not e_bits_0_i));
|
136 |
|
|
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'
|
137 |
|
|
start_multiplier <= start_multiplier_del_i and running_i;
|
138 |
|
|
|
139 |
|
|
-- start/stop logic
|
140 |
|
|
start_cycle_i <= (start and (not buffer_empty)) or next_bit_i; -- start pulse (external or internal)
|
141 |
|
|
done_i <= (start and buffer_empty) or (next_bit_i and bit_counter_0_i and buffer_empty); -- stop when buffer is empty
|
142 |
|
|
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));
|
143 |
|
|
|
144 |
|
|
-- process for delaying signals with 1 clock cycle
|
145 |
|
|
DEL_PROC: process(clk)
|
146 |
|
|
begin
|
147 |
|
|
if rising_edge(clk) then
|
148 |
|
|
start_multiplier_del_i <= start_multiplier_i;
|
149 |
|
|
start_cycle_del_i <= start_cycle_i;
|
150 |
|
|
mult_done_del_i <= multiplier_done;
|
151 |
|
|
end if;
|
152 |
|
|
end process DEL_PROC;
|
153 |
|
|
|
154 |
|
|
-- process for delaying signals with 1 clock cycle
|
155 |
|
|
CYCLE_CNTR_PROC: process(clk, start)
|
156 |
|
|
begin
|
157 |
|
|
if start = '1' or reset = '1' then
|
158 |
|
|
cycle_counter_i <= '0';
|
159 |
|
|
elsif rising_edge(clk) then
|
160 |
|
|
if (e_bits_0_i = '0') and (multiplier_done = '1') then
|
161 |
|
|
cycle_counter_i <= not cycle_counter_i;
|
162 |
|
|
elsif (e_bits_0_i = '1') and (multiplier_done = '1') then
|
163 |
|
|
cycle_counter_i <= '0';
|
164 |
|
|
else
|
165 |
|
|
cycle_counter_i <= cycle_counter_i;
|
166 |
|
|
end if;
|
167 |
|
|
end if;
|
168 |
|
|
end process CYCLE_CNTR_PROC;
|
169 |
|
|
|
170 |
|
|
end Behavioral;
|
171 |
|
|
|