-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathalu.vhd
95 lines (75 loc) · 3.42 KB
/
alu.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
83
84
85
86
87
88
89
90
91
92
93
94
95
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 17.02.2018 17:04:24
-- Design Name:
-- Module Name: alu - Behavioral
-- Project Name:
-- Target Devices:
-- Tool Versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity alu is
Port ( op1 : in STD_LOGIC_VECTOR (31 downto 0);
op2 : in STD_LOGIC_VECTOR (31 downto 0);
opc : in STD_LOGIC_VECTOR (3 downto 0);
carry : in STD_LOGIC_VECTOR(0 downto 0); -- conversion std_logic -> signed ??
op3 : out STD_LOGIC_VECTOR (31 downto 0);
flags : out STD_LOGIC_VECTOR (3 downto 0));
end alu;
--flag terminology + setF terminology -> NZVC
architecture Behavioral of alu is
signal outtemp: std_logic_vector (31 downto 0);
signal setF: std_logic_vector(3 downto 0);
signal c31: std_logic;
signal c32: std_logic;
signal noresult: std_logic;
begin
-- setF <= "0000";
-- noresult <= '0';
-- flags <= "0000";
outtemp <= (op1 and op2) when opc="0000" else
(op1 xor op2) when opc="0001" else
(std_logic_vector(signed(op1)+signed(not op2)+1)) when opc="0010" else
(std_logic_vector(signed(not op1)+1+signed(op2))) when opc="0011" else
(std_logic_vector(signed(op1)+signed(op2))) when opc="0100" else
(std_logic_vector(signed(op1)+signed(op2)+signed(carry))) when opc="0101" else
(std_logic_vector(signed(op1)+signed(not op2)+signed(carry))) when opc="0110" else
(std_logic_vector(signed(not op1)+signed(op2)+signed(carry))) when opc="0111" else
(op1 and op2) when opc="1000" else
(op1 xor op2) when opc="1001" else
(std_logic_vector(signed(op1)+signed(not op2)+1)) when opc="1010" else
(std_logic_vector(signed(not op1)+1+signed(op2))) when opc="1011" else
(op1 or op2) when opc="1100" else
(op2) when opc="1101" else
(op1 and (not op2)) when opc="1111" else
not op2;
noresult <= '1' when (opc="1000" or opc="1001" or opc="1010" or opc="1011") else
'0';
setF(3 downto 2) <= "11" when (opc="1100" or opc="1101" or opc="1110" or opc="1111" or opc="1000" or opc="0000" or opc="0001" or opc="1001");
setF(3 downto 0) <= "1111" when (opc="0010" or opc="0011" or opc="0100" or opc="0101" or opc="0110" or opc="0111" or opc="1010" or opc="1011");
flags(3) <= '1' when (setF(3)='1' and outtemp(31)='1');
flags(2) <= '1' when (setF(2)='1' and outtemp="0000000000000000000000000000000");
c31 <= (op1(31) xor op2(31) xor outtemp(31));
c32 <= ((op1(31) and c31) xor (op2(31) and c31) xor (op2(31) and op1(31)));
flags(0) <= c32 when (setF(0) = '1');
flags(1) <= (c32 xor c31) when(setF(1)='1');
op3 <= outtemp when (noresult = '0');
end Behavioral;