OpenCores
URL https://opencores.org/ocsvn/igor/igor/trunk

Subversion Repositories igor

[/] [igor/] [trunk/] [processor/] [pl/] [alu.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 atypic
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.std_logic_unsigned.all;
4
use ieee.numeric_std.all;
5
use work.leval2_package.all;
6
 
7
entity alu is
8
        port (
9
                in_a            : in std_logic_vector(OBJECT_SIZE-1 downto 0);
10
                in_b            : in std_logic_vector(OBJECT_SIZE-1 downto 0);
11
                funct           : in std_logic_vector(ALU_FUNCT_SIZE-1 downto 0);
12
                status  : out std_logic_vector(STATUS_REG_BITS-1 downto 0);
13
                output  : out std_logic_vector(OBJECT_SIZE-1 downto 0));
14
end entity alu;
15
 
16
architecture rtl of alu is
17
 
18
        signal mul_res : std_logic_vector(DATUM_SIZE*2-3 downto 0);
19
 
20
        signal type_a : std_logic_vector(INSTR_TYPE_BITS-1 downto 0);
21
        signal gc_flag_a : std_logic;
22
        signal datum_a : std_logic_vector(DATUM_SIZE-1 downto 0);
23
        signal type_b : std_logic_vector(INSTR_TYPE_BITS-1 downto 0);
24
        signal gc_flag_b : std_logic;
25
        signal datum_b : std_logic_vector(DATUM_SIZE-1 downto 0);
26
        signal type_r : std_logic_vector(INSTR_TYPE_BITS-1 downto 0);
27
        signal gc_flag_r : std_logic;
28
        signal datum_r : std_logic_vector(DATUM_SIZE-1 downto 0);
29
 
30
begin
31
 
32
        -- Decode inputs
33
        type_a <= in_a(OBJECT_SIZE-1 downto 27);
34
        gc_flag_a <= in_a(26);
35
        datum_a <= in_a(25 downto 0);
36
        type_b <= in_b(OBJECT_SIZE-1 downto 27);
37
        gc_flag_b <= in_b(26);
38
        datum_b <= in_b(25 downto 0);
39
 
40
        -- SET STATUS FLAGS
41
        -- Overflow
42
        status(OVERFLOW) <= '0' when (mul_res(49 downto 25) = (mul_res(49 downto 25) xor mul_res(49 downto 25))) else '1';
43
        -- negative
44
        status(NEG) <= datum_r(25);
45
        -- zero
46
        status(ZERO) <= '1' when datum_r = (datum_r xor datum_r) else '0';
47
        -- type error
48
        status(TYP) <= '0' when type_a = type_b else '1';
49
        -- io-error
50
        status(IO) <= '0';
51
        --unused
52
        status(1) <= '0';
53
        status(6) <= '0';
54
        status(7) <= '0';
55
 
56
        mul_res <= (datum_a(24 downto 0) * datum_b(24 downto 0));
57
 
58
        -- set output to result
59
        output <= type_r & gc_flag_r & datum_r;
60
 
61
        process(funct, type_a, type_b, gc_flag_a, gc_flag_b, datum_a, datum_b, mul_res)
62
        begin
63
                type_r <= (others => '0');
64
                gc_flag_r <= '0';
65
                datum_r  <= (others => '0');
66
                case funct is
67
                        when ALU_ADD =>
68
                                type_r <= type_a;
69
                                gc_flag_r <= gc_flag_a;
70
                                datum_r <= datum_a + datum_b;
71
 
72
                        when ALU_SUB =>
73
                                type_r <= type_a;
74
                                gc_flag_r <= gc_flag_a;
75
                                datum_r <= datum_a - datum_b;
76
 
77
                        when ALU_MUL =>
78
                                type_r <= type_a;
79
                                gc_flag_r <= gc_flag_a;
80
                                datum_r(24 downto 0) <= mul_res(24 downto 0);
81
                                datum_r(25) <= datum_a(25) xor datum_b(25);
82
 
83
 
84
                        when ALU_AND =>
85
                                type_r <= type_a;
86
                                gc_flag_r <= gc_flag_a;
87
                                datum_r <= datum_a and datum_b;
88
 
89
                        when ALU_OR =>
90
                                type_r <= type_a;
91
                                gc_flag_r <= gc_flag_a;
92
                                datum_r <= datum_a or datum_b;
93
 
94
                        when ALU_XOR =>
95
                                type_r <= type_a;
96
                                gc_flag_r <= gc_flag_a;
97
                                datum_r <= datum_a xor datum_b;
98
 
99
                        when ALU_GET_TYPE =>
100
                                type_r <= DT_INT;
101
                                gc_flag_r <= '0';
102
                                datum_r(INSTR_TYPE_BITS - 1 downto 0) <= type_b;
103
                                datum_r(DATUM_SIZE - 1 downto INSTR_TYPE_BITS) <= (others => '0');
104
 
105
                        when ALU_SET_TYPE =>
106
                                type_r <= datum_b(INSTR_TYPE_BITS-1 downto 0);
107
                                gc_flag_r <= '0';
108
                                datum_r <= datum_a;
109
 
110
                        when ALU_SET_DATUM =>
111
                                type_r <= type_a;
112
                                gc_flag_r <= gc_flag_a;
113
                                datum_r <= datum_b;
114
 
115
                        when ALU_SET_GC =>
116
                                type_r <= type_a;
117
                                gc_flag_r <= datum_b(0);
118
                                datum_r <= datum_a;
119
 
120
                        when ALU_GET_GC =>
121
                                type_r <= DT_INT;
122
                                gc_flag_r <= '0';
123
                                datum_r(0) <= gc_flag_b;
124
                                datum_r(DATUM_SIZE - 1 downto 1) <= (others => '0');
125
 
126
                        when ALU_CPY =>
127
                                type_r <= type_b;
128
                                gc_flag_r <= gc_flag_b;
129
                                datum_r <= datum_b;
130
 
131
                        -- shift right
132
                        when ALU_SR =>
133
                                type_r <= type_a;
134
                                gc_flag_r <= gc_flag_a;
135
                                datum_r <= std_logic_vector(shift_right(unsigned(datum_a),
136
                                        to_integer(unsigned(datum_b))));
137
 
138
                        -- shift left
139
                        when ALU_SL =>
140
                                type_r <= type_a;
141
                                gc_flag_r <= gc_flag_a;
142
                                datum_r <= std_logic_vector(shift_left(unsigned(datum_a),
143
                                        to_integer(unsigned(datum_b))));
144
 
145
                        when ALU_CMP_DATUM =>
146
                                type_r <= type_a;
147
                                gc_flag_r <= gc_flag_a;
148
                                datum_r <= datum_a - datum_b;
149
 
150
                        when ALU_CMP_TYPE =>
151
                                type_r <= type_a;
152
                                gc_flag_r <= gc_flag_a;
153
                                datum_r <= "000000000000000000000" & (type_a - type_b);
154
 
155
                        when ALU_CMP_TYPE_IMM =>
156
                                type_r <= type_a;
157
                                gc_flag_r <= gc_flag_a;
158
                                datum_r <= "000000000000000000000" & (type_a - datum_b(INSTR_TYPE_BITS - 1 downto 0));
159
 
160
                        when ALU_CMP_GC =>
161
                                type_r <= type_a;
162
                                gc_flag_r <= gc_flag_a;
163
                                datum_r <= "0000000000000000000000000"&(gc_flag_a xor gc_flag_b);
164
 
165
                        when ALU_CMP_GC_IMM =>
166
                                type_r <= type_a;
167
                                gc_flag_r <= gc_flag_a;
168
                                datum_r <= "0000000000000000000000000"&(gc_flag_a xor datum_b(0));
169
 
170
                        when ALU_CMP =>
171
                                if type_a = type_b and
172
                                        datum_a = datum_b then -- we have equivalent objects
173
                                        datum_r <= (others => '0');
174
                                else
175
                                        datum_r(DATUM_SIZE-1 downto DATUM_SIZE-4) <= "1111";
176
                                        datum_r(DATUM_SIZE-5 downto 0) <= (others => '0'); -- not same
177
                                end if;
178
 
179
                        when others =>
180
                                type_r <= (others => '0');
181
                                gc_flag_r <= '0';
182
                                datum_r  <= (others => '0');
183
 
184
                end case;
185
        end process;
186
end rtl;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.