Files
IEEE754Adder/Comparator.vhd

49 lines
887 B
VHDL
Raw Permalink Normal View History

2019-08-27 11:50:27 +02:00
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Comparator is
2019-08-29 15:12:25 +02:00
2019-08-29 18:08:25 +02:00
generic(
BITCOUNT : integer := 8
);
2019-08-29 15:12:25 +02:00
2019-08-27 11:50:27 +02:00
port(
2019-08-29 15:12:25 +02:00
X_MANT, Y_MANT : in std_logic_vector((BITCOUNT-1) downto 0);
NEED_SWAP : out std_logic
2019-08-27 11:50:27 +02:00
);
2019-08-29 15:12:25 +02:00
2019-08-27 11:50:27 +02:00
end Comparator;
architecture ComparatorArch of Comparator is
2019-08-29 15:12:25 +02:00
signal X_GT_Y : std_logic_vector((BITCOUNT-1) downto 0);
signal Y_GT_X : std_logic_vector((BITCOUNT-1) downto 0);
2019-08-27 11:50:27 +02:00
begin
2019-08-29 15:12:25 +02:00
X_GT_Y <= X_MANT and (not Y_MANT);
Y_GT_X <= (not X_MANT) and Y_MANT;
2019-08-29 18:08:25 +02:00
NEED_SWAP_PROCESS : process (X_GT_Y, Y_GT_X)
2019-08-29 15:12:25 +02:00
variable SWAP : std_logic;
variable SWAP_CARRY : std_logic;
2019-08-27 11:50:27 +02:00
begin
2019-08-29 15:12:25 +02:00
SWAP := '0';
SWAP_CARRY := '1';
2019-08-27 11:50:27 +02:00
for i in (BITCOUNT-1) downto 0 loop
2019-08-29 15:12:25 +02:00
SWAP := SWAP or ((not(X_GT_Y(i)) and Y_GT_X(i)) and SWAP_CARRY);
SWAP_CARRY := SWAP_CARRY and (not(X_GT_Y(i) and not(Y_GT_X(i))));
2019-08-27 11:50:27 +02:00
end loop;
2019-08-29 15:12:25 +02:00
NEED_SWAP <= SWAP;
2019-08-27 11:50:27 +02:00
end process;
end ComparatorArch;