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 3

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

powered by: WebSVN 2.1.0

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