-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMAC_Booth_0_1.vhd
62 lines (38 loc) · 1.44 KB
/
MAC_Booth_0_1.vhd
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
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;
USE ieee.std_logic_signed.ALL;
entity booth_multiplier is
generic ( termSize : integer := 4);
port ( mt : in std_logic_vector(termSize - 1 downto 0);
mr : in std_logic_vector(termSize - 1 downto 0);
result : out std_logic_vector(2*termSize - 1 downto 0));
end booth_multiplier;
architecture Behavioral of booth_multiplier is
begin
process(mt, mr)
constant zeros : std_logic_vector(termSize - 1 downto 0) := (others => '0');
constant resultSize : integer := 2 * termSize;
variable mtComp : std_logic_vector(termSize - 1 downto 0);
variable accMr : std_logic_vector(resultSize downto 0) := (others => '0');
variable temp : std_logic_vector(termSize - 1 downto 0);
begin
accMr(resultSize downto termSize + 1) := (others => '0');
accMr(termSize downto 1) := mr;
accMr(0) := '0';
if (mt /= zeros and mr /= zeros)then
for iter in 1 to termSize loop
temp := accMr(resultSize downto termSize + 1);
mtComp := not (mt) + 1;
if (accMr(1 downto 0) = "10") then
temp := temp + mtComp;
elsif (accMr(1 downto 0) = "01") then
temp := temp + mt;
end if;
accMr(resultSize downto termSize + 1) := temp;
accMr(resultSize - 1 downto 0) := accMr(resultSize downto 1);
end loop;
end if;
result <= accMr(resultSize downto 1);
end process;
end Behavioral;