-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbooth_multiplier.vhd
65 lines (41 loc) · 1.35 KB
/
booth_multiplier.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
60
61
62
63
64
65
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_signed.ALL;
ENTITY booth_multiplier IS
GENERIC (x : INTEGER := 8;
y : INTEGER := 8);
PORT(m : IN STD_LOGIC_VECTOR(x - 1 DOWNTO 0);
r : IN STD_LOGIC_VECTOR(y - 1 DOWNTO 0);
result : OUT STD_LOGIC_VECTOR(x + y - 1 DOWNTO 0));
END booth_multiplier;
ARCHITECTURE behavior OF booth_multiplier IS
BEGIN
PROCESS(m, r)
CONSTANT X_ZEROS : STD_LOGIC_VECTOR(x - 1 DOWNTO 0) := (OTHERS => '0');
CONSTANT Y_ZEROS : STD_LOGIC_VECTOR(y - 1 DOWNTO 0) := (OTHERS => '0');
VARIABLE a, s, p : STD_LOGIC_VECTOR(x + y + 1 DOWNTO 0);
VARIABLE mn : STD_LOGIC_VECTOR(x - 1 DOWNTO 0);
BEGIN
a := (OTHERS => '0');
s := (OTHERS => '0');
p := (OTHERS => '0');
IF (m /= X_ZEROS AND r /= Y_ZEROS) THEN
a(x + y DOWNTO y + 1) := m;
a(x + y + 1) := m(x - 1);
mn := (NOT m) + 1;
s(x + y DOWNTO y + 1) := mn;
s(x + y + 1) := NOT(m(x - 1));
p(y DOWNTO 1) := r;
FOR i IN 1 TO y LOOP
IF (p(1 DOWNTO 0) = "01") THEN
p := p + a;
ELSIF (p(1 DOWNTO 0) = "10") THEN
p := p + s;
END IF;
-- Shift Right Arithmetic
p(x + y DOWNTO 0) := p(x + y + 1 DOWNTO 1);
END LOOP;
END IF;
result <= p(x + y DOWNTO 1);
END PROCESS;
END behavior;