-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDENORMALIZED_SUM.vhd
83 lines (69 loc) · 2.1 KB
/
DENORMALIZED_SUM.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity DENORMALIZED_SUM is
port(
X : in std_logic_vector(24 downto 0);
Y : in std_logic_vector(24 downto 0);
M : out std_logic_vector(23 downto 0);
SIGN : out std_logic;
INCR : out std_logic -- indicats if the the exponent will have to be incremented by one
);
end DENORMALIZED_SUM;
architecture Behavioral of DENORMALIZED_SUM is
component RCA is
generic( width : integer);
port(
X : in std_logic_vector (width - 1 downto 0);
Y : in std_logic_vector (width - 1 downto 0);
CIN : in std_logic;
S : out std_logic_vector (width - 1 downto 0);
COUT : out std_logic
);
end component;
component PA is -- calculates the result's 2's complement if necessary
generic( width : integer);
port(
X : in std_logic_vector (width - 1 downto 0);
CIN : in std_logic;
S : out std_logic_vector (width - 1 downto 0);
COUT : out std_logic
);
end component;
component MUX is -- selects between the result and it's 2's complement
generic( width : integer);
port(
X : in std_logic_vector (width - 1 downto 0);
Y : in std_logic_vector (width - 1 downto 0);
S : in std_logic;
Z : out std_logic_vector (width - 1 downto 0)
);
end component;
signal S : std_logic_vector(25 downto 0);
signal NEGS : std_logic_vector(23 downto 0);
begin
U1: RCA -- each number has 1 sign bit, 1 extra bit for overflows, 1 extra 1 (not shown in mantissa), 23 mantissa bits
generic map(width => 26)
port map(
X => X(24) & X, -- adding the extra overflow bit (1 if the number is negative, 0 if positive)
Y => Y(24) & Y, -- adding the extra overflow bit (1 if the number is negative, 0 if positive)
CIN => X(24), -- if X is negative, it need to be converted to the 2's complement
S => S
);
INCR <= S(24) xor S(25);
SIGN <= S(25);
U2: PA
generic map(width => 24)
port map(
X => not S(23 downto 0),
CIN => '1',
S => NEGS
);
U3: MUX
generic map(width => 24)
port map(
X => S(23 downto 0),
Y => NEGS,
S => S(25),
Z => M
);
end Behavioral;