1
|
library ieee;
|
2
|
use ieee.std_logic_1164.all;
|
3
|
|
4
|
library ieee;
|
5
|
use ieee.numeric_std.all;
|
6
|
|
7
|
entity sub_160 is
|
8
|
port (
|
9
|
output : out std_logic_vector(63 downto 0);
|
10
|
lt : out std_logic;
|
11
|
le : out std_logic;
|
12
|
sign : in std_logic;
|
13
|
ge : out std_logic;
|
14
|
in_a : in std_logic_vector(63 downto 0);
|
15
|
in_b : in std_logic_vector(63 downto 0)
|
16
|
);
|
17
|
end sub_160;
|
18
|
|
19
|
architecture augh of sub_160 is
|
20
|
|
21
|
signal carry_inA : std_logic_vector(65 downto 0);
|
22
|
signal carry_inB : std_logic_vector(65 downto 0);
|
23
|
signal carry_res : std_logic_vector(65 downto 0);
|
24
|
|
25
|
-- Signals to generate the comparison outputs
|
26
|
signal msb_abr : std_logic_vector(2 downto 0);
|
27
|
signal tmp_sign : std_logic;
|
28
|
signal tmp_eq : std_logic;
|
29
|
signal tmp_le : std_logic;
|
30
|
signal tmp_ge : std_logic;
|
31
|
|
32
|
begin
|
33
|
|
34
|
-- To handle the CI input, the operation is '0' - CI
|
35
|
-- If CI is not present, the operation is '0' - '0'
|
36
|
carry_inA <= '0' & in_a & '0';
|
37
|
carry_inB <= '0' & in_b & '0';
|
38
|
-- Compute the result
|
39
|
carry_res <= std_logic_vector(unsigned(carry_inA) - unsigned(carry_inB));
|
40
|
|
41
|
-- Set the outputs
|
42
|
output <= carry_res(64 downto 1);
|
43
|
|
44
|
-- Other comparison outputs
|
45
|
|
46
|
-- Temporary signals
|
47
|
msb_abr <= in_a(63) & in_b(63) & carry_res(64);
|
48
|
tmp_sign <= sign;
|
49
|
tmp_eq <= '1' when in_a = in_b else '0';
|
50
|
|
51
|
tmp_le <=
|
52
|
tmp_eq when msb_abr = "000" or msb_abr = "110" else
|
53
|
'1' when msb_abr = "001" else
|
54
|
'1' when tmp_sign = '0' and (msb_abr = "010" or msb_abr = "001" or msb_abr = "111") else
|
55
|
'1' when tmp_sign = '1' and (msb_abr = "100" or msb_abr = "101") else
|
56
|
'0';
|
57
|
|
58
|
tmp_ge <=
|
59
|
'1' when msb_abr = "000" or msb_abr = "110" else
|
60
|
'1' when tmp_sign = '0' and (msb_abr = "100" or msb_abr = "101") else
|
61
|
'1' when tmp_sign = '1' and (msb_abr = "010" or msb_abr = "011" or msb_abr = "111") else
|
62
|
'0';
|
63
|
|
64
|
ge <= tmp_ge;
|
65
|
lt <= not(tmp_ge);
|
66
|
le <= tmp_le;
|
67
|
|
68
|
end architecture;
|