Files
IEEE754Adder/Adder.vhd

54 lines
1.1 KiB
VHDL
Raw Normal View History

2019-08-28 21:50:05 +02:00
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Adder is
2019-08-29 18:08:25 +02:00
generic(
BITCOUNT : integer := 8
);
2019-08-28 21:50:05 +02:00
port(
2019-08-29 18:08:25 +02:00
X, Y : in std_logic_vector((BITCOUNT-1) downto 0);
CARRY_IN : in std_logic;
RESULT : out std_logic_vector((BITCOUNT-1) downto 0);
CARRY_OUT : out std_logic
2019-08-28 21:50:05 +02:00
);
2019-08-29 18:08:25 +02:00
2019-08-28 21:50:05 +02:00
end Adder;
architecture CarryLookAheadArch of Adder is
2019-08-29 18:08:25 +02:00
signal GENERATION : std_logic_vector((BITCOUNT-1) downto 0);
signal PROPAGATION : std_logic_vector((BITCOUNT-1) downto 0);
signal CARRY : std_logic_vector((BITCOUNT-1) downto 0);
signal SUM_NO_CARRY : std_logic_vector((BITCOUNT-1) downto 0);
2019-08-28 21:50:05 +02:00
begin
2019-08-29 18:08:25 +02:00
GENERATION <= X and Y;
PROPAGATION <= X or Y;
SUM_NO_CARRY <= X xor Y;
CARRY_LOOK_AHEAD_PROCESS : process (GENERATION, PROPAGATION, CARRY_IN)
variable C : std_logic;
2019-08-28 21:50:05 +02:00
begin
2019-08-29 18:08:25 +02:00
C := CARRY_IN;
CARRY(0) <= C;
for i in 1 to (BITCOUNT-1) loop
2019-08-29 18:08:25 +02:00
C := GENERATION(i-1) or (PROPAGATION(i-1) and C);
CARRY(i) <= C;
2019-08-28 21:50:05 +02:00
end loop;
2019-08-29 18:08:25 +02:00
2019-08-28 21:50:05 +02:00
end process;
2019-08-29 18:08:25 +02:00
RESULT <= SUM_NO_CARRY xor CARRY;
CARRY_OUT <= (X(BITCOUNT-1) and Y(BITCOUNT-1)) or (X(BITCOUNT-1) and CARRY(BITCOUNT-1)) or (CARRY(BITCOUNT-1) and Y(BITCOUNT-1));
2019-08-28 21:50:05 +02:00
end CarryLookAheadArch;