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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
| library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;
use work.c31L_pack.all;
entity alu32 is
port( RI : in std_logic;
a_alu32 : buffer std_logic_vector(BW-1 downto 0);
b_alu32 : buffer std_logic_vector(BW-1 downto 0);
alu_op : in alu_function_type;--operation code
g : out std_logic; --greater
e : out std_logic; --equal
l : out std_logic; --less
o_alu32 : buffer std_logic_vector(BW-1 downto 0); --output
c_alu32 : inout std_logic; --carry
ov_alu32 : out std_logic); --overflow flag
end alu32;
architecture Behavioral of alu32 is
COMPONENT alu_1bit
Port (A : in STD_LOGIC;
B : in STD_LOGIC;
cin: in STD_LOGIC;
opsel : in STD_LOGIC_VECTOR (3 DOWNTO 0);
output : out STD_LOGIC;
cout : out STD_LOGIC);
END COMPONENT;
COMPONENT comparator
PORT (in_0 : IN STD_LOGIC ;
in_1 : IN STD_LOGIC ;
greater_in : IN STD_LOGIC;
equal_in : IN STD_LOGIC;
less_in : IN STD_LOGIC;
greater : OUT STD_LOGIC ;
equal : OUT STD_LOGIC ;
less : OUT STD_LOGIC);
END COMPONENT;
signal carry :std_logic_vector(BW downto 0);
signal gs, es, ls : std_logic_vector (BW-1 downto 0);
begin
process(RI, a_alu32, b_alu32, alu_op)
variable o_alu32var: std_logic_vector(BW-1 downto 0);
begin
case alu_op is
---None---
when (alu_op = "0000") =>
o_alu32 <= "00000000000000000000000000000000";
---move/I---
when (alu_op="1011") =>
if (RI='0') then
o_alu32 <= a_alu32;
else
o_alu32 <= b_alu32;
end if;
---SLL---
when (alu_op="1001") =>
o_alu32 <= to_stdlogicvector(to_bitvector(a_alu32) SLL (to_integer(b_alu32)));
---arthmetic and logic---
when (alu_op="0001" or alu_op="0010" or alu_op="0101" or
alu_op="0110" or alu_op="0111" or alu_op="1000") =>
carry(0) <= '0';
z1: FOR i IN 0 to BW-1 loop
a1: alu_1bit port map(a_alu32(i), b_alu32(i), carry(i), alu_op, o_alu32var(i), carry(i+1));
END loop z1;
c_alu32<=carry(BW);
ov_alu32 <= (a_alu32(31) and b_alu32(31) and not o_alu32(31)) or (not a_alu32(31) and not b_alu32(31) and o_alu32(31)) when (alu_op = "0001" or alu_op = "0010")
else '0';
---COMP---
when (alu_op = "0011") =>
gs(0) <= '0';
ls(0) <= '0';
es(0) <= '1';
g1: for i in 0 to BW-1 loop
comparator32: comparator port map(a_alu32(i), b_alu32(i), gs(i), es(i), ls(i), gs(i+1), es(i+1), ls(i+1));
END loop g1;
g <= gs(BW);
e <= es(BW);
l <= ls(BW);
END CASE;
END PROCESS;
end Behavioral; |