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/] [autorun_cntrl.vhd] - Blame information for rev 95

Details | Compare with Previous | View Log

Line No. Rev Author Line
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 95 JonasDC
 
74 3 JonasDC
  signal start_cycle_i     : std_logic := '0';
75
  signal start_cycle_del_i : std_logic;
76 95 JonasDC
 
77 3 JonasDC
  signal done_i    : std_logic;
78
  signal running_i : std_logic;
79 95 JonasDC
 
80 3 JonasDC
  signal start_multiplier_i     : std_logic;
81
  signal start_multiplier_del_i : std_logic;
82
  signal mult_done_del_i        : std_logic;
83 95 JonasDC
 
84 3 JonasDC
  signal e0_bit_i        : std_logic;
85
  signal e1_bit_i        : std_logic;
86
  signal e_bits_i        : std_logic_vector(1 downto 0);
87
  signal e_bits_0_i      : std_logic;
88
  signal cycle_counter_i : std_logic;
89
  signal op_sel_sel_i    : std_logic;
90
  signal op_sel_i        : std_logic_vector(1 downto 0);
91 95 JonasDC
 
92
  signal exponent_shift_i : std_logic_vector(31 downto 0);
93
  signal read_buffer_i    : std_logic;
94
  signal read_buffer_i_d  : std_logic;
95 3 JonasDC
begin
96 2 JonasDC
 
97 95 JonasDC
  done <= done_i;
98
  read_buffer <= read_buffer_i;
99 2 JonasDC
 
100 95 JonasDC
  -- generate the index to select a single bit from the two exponents
101
  SYNC_BIT_COUNTER : process (clk, reset)
102
  begin
103
    if reset = '1' then
104
      bit_counter_i <= 15;
105
    elsif rising_edge(clk) then
106
      if start = '1' then -- make sure we start @ bit 0
107
        bit_counter_i <= 15;
108
      elsif next_bit_i = '1' then -- count
109
        if bit_counter_i = 0 then
110
          bit_counter_i <= 15;
111
        else
112
          bit_counter_i <= bit_counter_i - 1;
113
        end if;
114
      end if;
115
    end if;
116
  end process SYNC_BIT_COUNTER;
117 2 JonasDC
 
118 95 JonasDC
  -- process that implements the shift register for the exponents
119
  -- more performant than former mux implementation
120
  EXP_SHIFTER : process (clk, reset)
121
  begin
122
    if reset = '1' then
123
      exponent_shift_i <= (others => '0');
124
    elsif rising_edge(clk) then
125
      read_buffer_i_d <= read_buffer_i; -- delay read_buffer signal one clock
126
      if read_buffer_i_d = '1' then -- after new buffer read, shift in new bits
127
        exponent_shift_i <= buffer_din;
128
      elsif next_bit_i = '1' then -- count
129
        exponent_shift_i(31 downto 1) <= exponent_shift_i(30 downto 0);
130
      end if;
131
    end if;
132
  end process EXP_SHIFTER;
133
 
134
  -- signal when bit_counter_i = 0
135
  bit_counter_0_i <= '1' when bit_counter_i = 0 else '0';
136
  bit_counter_15_i <= '1' when bit_counter_i = 15 else '0';
137
  -- the bits...
138
  e0_bit_i <= exponent_shift_i(15);
139
  e1_bit_i <= exponent_shift_i(31);
140
  e_bits_i <= e0_bit_i & e1_bit_i;
141
  e_bits_0_i <= '1' when (e_bits_i = "00") else '0';
142
 
143
  -- operand pre-select
144
  with e_bits_i select
145
    op_sel_i <= "00" when "10", -- gt0
146
                "01" when "01", -- gt1
147
                "10" when "11", -- gt01
148
                "11" when others;
149
 
150
  -- select operands
151
  op_sel_sel_i <= '0' when e_bits_0_i = '1' else (cycle_counter_i);
152
  op_sel <= op_sel_i when op_sel_sel_i = '1' else "11";
153
 
154
  -- process that drives running_i signal ('1' when in autorun, '0' when not)
155
  RUNNING_PROC : process(clk, reset)
156
  begin
157
    if reset = '1' then
158
      running_i <= '0';
159
    elsif rising_edge(clk) then
160
      running_i <= start or (running_i and (not done_i));
161
    end if;
162
  end process RUNNING_PROC;
163
 
164
  -- ctrl logic
165
  start_multiplier_i <= start_cycle_del_i or (mult_done_del_i and (cycle_counter_i) and (not e_bits_0_i));
166
  read_buffer_i <= start_cycle_del_i and bit_counter_15_i and running_i; -- pop new word from fifo when bit_counter is back at '15'
167
  start_multiplier <= start_multiplier_del_i and running_i;
168
 
169
  -- start/stop logic
170
  start_cycle_i <= (start and (not buffer_empty)) or next_bit_i; -- start pulse (external or internal)
171
  done_i <= (start and buffer_empty) or (next_bit_i and bit_counter_0_i and buffer_empty); -- stop when buffer is empty
172
  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));
173
 
174
  -- process for delaying signals with 1 clock cycle
175
  DEL_PROC : process(clk)
176
  begin
177
    if rising_edge(clk) then
178
      start_multiplier_del_i <= start_multiplier_i;
179
      start_cycle_del_i <= start_cycle_i;
180
      mult_done_del_i <= multiplier_done;
181
    end if;
182
  end process DEL_PROC;
183
 
184
  -- process for cycle counter
185
  CYCLE_CNTR_PROC : process(clk, start, reset)
186
  begin
187
    if start = '1' or reset = '1' then
188
      cycle_counter_i <= '0';
189
    elsif rising_edge(clk) then
190
      if (e_bits_0_i = '0') and (multiplier_done = '1') then
191
        cycle_counter_i <= not cycle_counter_i;
192
      elsif (e_bits_0_i = '1') and (multiplier_done = '1') then
193
        cycle_counter_i <= '0';
194
      else
195
        cycle_counter_i <= cycle_counter_i;
196
      end if;
197
    end if;
198
  end process CYCLE_CNTR_PROC;
199
 
200 2 JonasDC
end Behavioral;

powered by: WebSVN 2.1.0

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