1 |
30 |
JonasDC |
----------------------------------------------------------------------
|
2 |
|
|
---- sys_last_cell_logic ----
|
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 |
|
|
---- last cell logic for use int the montogommery mulitplier ----
|
10 |
|
|
---- pipelined systolic array ----
|
11 |
|
|
---- ----
|
12 |
|
|
---- Dependencies: ----
|
13 |
|
|
---- - register_n ----
|
14 |
|
|
---- - cell_1b_adder ----
|
15 |
|
|
---- ----
|
16 |
|
|
---- Authors: ----
|
17 |
|
|
---- - Geoffrey Ottoy, DraMCo research group ----
|
18 |
|
|
---- - Jonas De Craene, JonasDC@opencores.org ----
|
19 |
|
|
---- ----
|
20 |
|
|
----------------------------------------------------------------------
|
21 |
|
|
---- ----
|
22 |
|
|
---- Copyright (C) 2011 DraMCo research group and OPENCORES.ORG ----
|
23 |
|
|
---- ----
|
24 |
|
|
---- This source file may be used and distributed without ----
|
25 |
|
|
---- restriction provided that this copyright statement is not ----
|
26 |
|
|
---- removed from the file and that any derivative work contains ----
|
27 |
|
|
---- the original copyright notice and the associated disclaimer. ----
|
28 |
|
|
---- ----
|
29 |
|
|
---- This source file is free software; you can redistribute it ----
|
30 |
|
|
---- and/or modify it under the terms of the GNU Lesser General ----
|
31 |
|
|
---- Public License as published by the Free Software Foundation; ----
|
32 |
|
|
---- either version 2.1 of the License, or (at your option) any ----
|
33 |
|
|
---- later version. ----
|
34 |
|
|
---- ----
|
35 |
|
|
---- This source is distributed in the hope that it will be ----
|
36 |
|
|
---- useful, but WITHOUT ANY WARRANTY; without even the implied ----
|
37 |
|
|
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----
|
38 |
|
|
---- PURPOSE. See the GNU Lesser General Public License for more ----
|
39 |
|
|
---- details. ----
|
40 |
|
|
---- ----
|
41 |
|
|
---- You should have received a copy of the GNU Lesser General ----
|
42 |
|
|
---- Public License along with this source; if not, download it ----
|
43 |
|
|
---- from http://www.opencores.org/lgpl.shtml ----
|
44 |
|
|
---- ----
|
45 |
|
|
----------------------------------------------------------------------
|
46 |
|
|
|
47 |
|
|
library ieee;
|
48 |
|
|
use ieee.std_logic_1164.all;
|
49 |
|
|
use ieee.std_logic_unsigned.all;
|
50 |
|
|
|
51 |
|
|
library mod_sim_exp;
|
52 |
|
|
use mod_sim_exp.mod_sim_exp_pkg.all;
|
53 |
|
|
|
54 |
|
|
-- logic needed as the last piece in the systolic array pipeline
|
55 |
|
|
-- calculates the last 2 bits of the cell_result and finishes the reduction
|
56 |
|
|
-- also generates the result selection signal
|
57 |
|
|
entity sys_last_cell_logic is
|
58 |
|
|
port (
|
59 |
|
|
core_clk : in std_logic; -- clock input
|
60 |
|
|
reset : in std_logic;
|
61 |
|
|
a_0 : out std_logic; -- a_msb for last stage
|
62 |
|
|
cin : in std_logic; -- cout from last stage
|
63 |
|
|
red_cin : in std_logic; -- red_cout from last stage
|
64 |
|
|
r_sel : out std_logic; -- result selection bit
|
65 |
|
|
start : in std_logic -- done signal from last stage
|
66 |
|
|
);
|
67 |
|
|
end sys_last_cell_logic;
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
architecture Behavorial of sys_last_cell_logic is
|
71 |
|
|
signal cell_result_high : std_logic_vector(1 downto 0);
|
72 |
|
|
signal cell_result_high_reg : std_logic_vector(1 downto 0);
|
73 |
|
|
signal red_cout_end : std_logic;
|
74 |
|
|
begin
|
75 |
|
|
|
76 |
|
|
-- half adder: cout_last_stage + cell_result_high_reg(1)
|
77 |
|
|
cell_result_high(0) <= cin xor cell_result_high_reg(1); --result
|
78 |
|
|
cell_result_high(1) <= cin and cell_result_high_reg(1); --cout
|
79 |
|
|
|
80 |
|
|
a_0 <= cell_result_high_reg(0);
|
81 |
|
|
|
82 |
|
|
last_reg : register_n
|
83 |
|
|
generic map(
|
84 |
|
|
width => 2
|
85 |
|
|
)
|
86 |
|
|
port map(
|
87 |
|
|
core_clk => core_clk,
|
88 |
|
|
ce => start,
|
89 |
|
|
reset => reset,
|
90 |
|
|
din => cell_result_high,
|
91 |
|
|
dout => cell_result_high_reg
|
92 |
|
|
);
|
93 |
|
|
|
94 |
|
|
-- reduction, finishing last 2 bits
|
95 |
|
|
reduction_adder_a : cell_1b_adder
|
96 |
|
|
port map(
|
97 |
|
|
a => '1', -- for 2s complement of m
|
98 |
|
|
b => cell_result_high_reg(0),
|
99 |
|
|
cin => red_cin,
|
100 |
|
|
cout => red_cout_end
|
101 |
|
|
);
|
102 |
|
|
|
103 |
|
|
reduction_adder_b : cell_1b_adder
|
104 |
|
|
port map(
|
105 |
|
|
a => '1', -- for 2s complement of m
|
106 |
|
|
b => cell_result_high_reg(1),
|
107 |
|
|
cin => red_cout_end,
|
108 |
|
|
cout => r_sel
|
109 |
|
|
);
|
110 |
|
|
|
111 |
|
|
end Behavorial;
|