-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkarasuba255bit.vhdl
98 lines (85 loc) · 2.61 KB
/
karasuba255bit.vhdl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
LIBRARY ieee;
USE IEEE.std_logic_1164.ALL;
USE IEEE.numeric_std.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY karasuba255bit IS
PORT (
clk : IN STD_LOGIC;
rest : IN STD_LOGIC;
start : IN STD_LOGIC;
a : IN STD_LOGIC_VECTOR(255 DOWNTO 0);
b : IN STD_LOGIC_VECTOR(255 DOWNTO 0);
p : OUT STD_LOGIC_VECTOR(511 DOWNTO 0) := (OTHERS => '0');
done : OUT STD_LOGIC := '0'
);
END karasuba255bit;
ARCHITECTURE arch OF karasuba255bit IS
SIGNAL half_one_1, half_one_2, half_two_1, half_two_2, sum_1, sum_2, sum_3 : STD_LOGIC_VECTOR(127 DOWNTO 0) := (OTHERS => '0');
SIGNAL result_1, result_2, result_3 : STD_LOGIC_VECTOR(255 DOWNTO 0);
SIGNAL flag : STD_LOGIC := '0';
SIGNAL done_1, done_2, done_3, final : STD_LOGIC := '0';
COMPONENT karasuba128bit IS
PORT (
clk : IN STD_LOGIC;
rest : IN STD_LOGIC;
start : IN STD_LOGIC;
a : IN STD_LOGIC_VECTOR(127 DOWNTO 0);
b : IN STD_LOGIC_VECTOR(127 DOWNTO 0);
p : OUT STD_LOGIC_VECTOR(255 DOWNTO 0) := (OTHERS => '0');
done : OUT STD_LOGIC
);
END COMPONENT karasuba128bit;
BEGIN
half_one_1 <= a(255 DOWNTO 128);
half_one_2 <= a(127 DOWNTO 0);
half_two_1 <= b(255 DOWNTO 128);
half_two_2 <= b(127 DOWNTO 0);
sum_1 <= half_one_1 + half_one_2;
sum_2 <= half_two_1 + half_two_2;
x : karasuba128bit
PORT MAP(
clk => clk,
rest => rest,
start => start,
a => half_one_1,
b => half_two_1,
p => result_1,
done => done_1
);
y : karasuba128bit
PORT MAP(
clk => clk,
rest => rest,
start => start,
a => half_one_2,
b => half_two_2,
p => result_2,
done => done_2
);
z : karasuba128bit
PORT MAP(
clk => clk,
rest => rest,
start => start,
a => sum_1,
b => sum_2,
p => result_3,
done => done_3
);
final <= done_1 AND done_2 AND done_3;
main : PROCESS
VARIABLE sum_temp : STD_LOGIC_VECTOR(63 DOWNTO 0);
VARIABLE z1 : STD_LOGIC_VECTOR(511 DOWNTO 0) := (OTHERS => '0');
VARIABLE z2 : STD_LOGIC_VECTOR(511 DOWNTO 0) := (OTHERS => '0');
VARIABLE z3 : STD_LOGIC_VECTOR(511 DOWNTO 0) := (OTHERS => '0');
BEGIN
flag <= '1';
WAIT UNTIL final = '1';
z1(511 DOWNTO 256) := result_1;
z2(383 DOWNTO 128) := result_3 - result_2 - result_1;
z3(255 DOWNTO 0) := result_2;
p <= z1 + z2 + z3;
done <= '1';
WAIT UNTIL flag = '0';
END PROCESS main;
END ARCHITECTURE;