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

Subversion Repositories ecpu_alu

[/] [ecpu_alu/] [trunk/] [alu/] [rtl/] [vhdl/] [alu_datapath.vhd] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 leonous
--------------------------------------------------------------------------------
2
--------------------------------------------------------------------------------
3
-- Module   - Introduction to VLSI Design [03ELD005]
4
-- Lecturer - Dr V. M. Dwyer
5
-- Course   - MEng Electronic and Electrical Engineering
6
-- Year     - Part D
7
-- Student  - Sahrfili Leonous Matturi A028459 [elslm]
8
--------------------------------------------------------------------------------
9
--------------------------------------------------------------------------------
10
-- Final coursework 2004
11
-- 
12
-- Details:     Design and Layout of an ALU
13
--------------------------------------------------------------------------------
14
--------------------------------------------------------------------------------
15
 
16
--      Description     :       ALU datapath description
17
--  Entity                      :       alu_datapath
18
--      Architecture    :       behavioural
19
--  Created on          :       07/03/2004
20
 
21
library ieee;
22
 
23
use ieee.std_logic_1164.all;
24
use     ieee.std_logic_unsigned.all;
25
 
26
entity alu_datapath is
27
        generic (
28
                        ALU_WIDTH : integer := 8
29
                        );
30
        port    (
31
                        A                       : in    std_logic_vector(ALU_WIDTH - 1 downto 0);
32
                        B                       : in    std_logic_vector(ALU_WIDTH - 1 downto 0);
33
                        Y                       : out   std_logic_vector(ALU_WIDTH - 1 downto 0);
34
 
35
                        add_AB          : in    std_logic;      -- ALU control commands
36
                        sub_AB          : in    std_logic;
37
                        inc_A           : in    std_logic;
38
                        inc_B           : in    std_logic;
39
                        dec_A           : in    std_logic;
40
                        dec_B           : in    std_logic;
41
                        cmp_AB          : in    std_logic;
42
                        and_AB          : in    std_logic;
43
                        or_AB           : in    std_logic;
44
                        xor_AB          : in    std_logic;
45
                        cpl_B           : in    std_logic;
46
                        cpl_A           : in    std_logic;
47
                        sl_AB           : in    std_logic;
48
                        sr_AB           : in    std_logic;
49
                        clr                     : in    std_logic;      -- soft reset! via opcode
50
 
51
                        clr_Z           : in    std_logic;
52
                        clr_V           : in    std_logic;
53
                        clr_C           : in    std_logic;
54
 
55
                        C                       : out   std_logic;      -- carry flag
56
                        V                       : out   std_logic;  -- overflow flag
57
                        Z                       : out   std_logic;      -- ALU result = 0
58
 
59
                        load_inputs     : in    std_logic;
60
                        load_outputs: in        std_logic;
61
 
62
                        reset           : in    std_logic;      -- hard reset!
63
 
64
                        clk                     : in    std_logic       -- clk signal
65
                        );
66
end alu_datapath;
67
 
68
architecture behavioural of alu_datapath is
69
component alu_adder
70
        generic (
71
                        adder_width     : integer := ALU_WIDTH
72
                        );
73
        port    (
74
                        x                       : in    std_logic_vector(ALU_WIDTH - 1 downto 0);
75
                        y                       : in    std_logic_vector(ALU_WIDTH - 1 downto 0);
76
                        carry_in        : in    std_logic                                                               ;
77
                        ORsel           : in    std_logic                                                               ;
78
                        XORsel          : in    std_logic                                                               ;
79
                        carry_out       : out   std_logic_vector(ALU_WIDTH         downto 0);
80
                        xor_result      : out   std_logic_vector(ALU_WIDTH - 1 downto 0);
81
                        or_result       : out   std_logic_vector(ALU_WIDTH - 1 downto 0);
82
                        and_result      : out   std_logic_vector(ALU_WIDTH - 1 downto 0);
83
                        z                       : out   std_logic_vector(ALU_WIDTH - 1 downto 0)
84
                        );
85
end component;
86
component mux8to1_1bit is
87
        PORT    (
88
                        sel                     : in            std_logic_vector(2 downto 0);
89
                        din0            : in            std_logic                                       ;
90
                        din1            : in            std_logic                                       ;
91
                        din2            : in            std_logic                                       ;
92
                        din3            : in            std_logic                                       ;
93
                        din4            : in            std_logic                                       ;
94
                        din5            : in            std_logic                                       ;
95
                        din6            : in            std_logic                                       ;
96
                        din7            : in            std_logic                                       ;
97
                        dout            : out           std_logic
98
                        );
99
end component;
100
component       alu_barrel_shifter
101
        port    (
102
                        x                       : in            std_logic_vector(7 downto 0);
103
                        y                       : in            std_logic_vector(7 downto 0);
104
                        z                       : out           std_logic_vector(7 downto 0);
105
                        c                       : out           std_logic                                       ;
106
                        direction       : in            std_logic
107
                        );
108
end component;
109
component mux2to1_1bit is
110
        port    (
111
                        sel                     : in            std_logic                                       ;
112
                        din0            : in            std_logic                                       ;
113
                        din1            : in            std_logic                                       ;
114
                        dout            : out           std_logic
115
                        );
116
end component;
117
 
118
signal  adder_in_a      ,
119
                adder_in_b      ,
120
                adder_out               : std_logic_vector(ALU_WIDTH - 1 downto 0)       ;
121
signal  shifter_inA     ,
122
                shifter_inB     ,
123
                shifter_out             : std_logic_vector(ALU_WIDTH - 1 downto 0)       ;
124
signal  shifter_carry,
125
                shifter_direction
126
                                                : std_logic                                                                     ;
127
signal  carry_in        ,
128
                carry           ,
129
                adderORsel      ,
130
                adderXORsel             : std_logic                                                                     ;
131
signal  carry_out               : std_logic_vector(ALU_WIDTH     downto 0)       ;
132
signal  Areg            ,
133
                Breg            ,
134
                Yreg            ,
135
                B_path          ,
136
                alu_out                 : std_logic_vector(ALU_WIDTH - 1 downto 0)       ;
137
signal  Zreg,
138
                Creg,
139
                Vreg                    : std_logic                                                                     ;
140
 
141
signal  AandB,
142
                AxorB,
143
                AorB                    : std_logic_vector(ALU_WIDTH - 1 downto 0)       ;
144
signal  logic1,
145
                logic0                  : std_logic_vector(ALU_WIDTH - 1 downto 0)       ;
146
begin
147
 
148
        logic1          <= (others => '1')      ;
149
        logic0          <= (others => '0')       ;
150
 
151
        -- assign registers to outputs
152
        Y               <= Yreg;
153
        Z               <= Zreg;
154
        C               <= Creg;
155
        V               <= Vreg;
156
 
157
        -- inputs to adder
158
        adder_in_a      <=      (others => '0') when (cpl_B = '1') else
159
                                        Areg ;
160
        adder_in_b      <=      Breg                    when
161
                                                (sub_AB = '0' and inc_A = '0' and cpl_B = '0') else
162
                                        not Breg                when
163
                                                ((sub_AB = '1' and inc_A = '0') or cpl_B = '1') else
164
                                        (others => '0') when
165
                                                (sub_AB = '0' and inc_A = '1' and cpl_B = '0');
166
 
167
        -- carry_in to adder is set to 1 during subtract and increment
168
        -- operations
169
        carry_in        <=      '1' when
170
                                                (sub_AB = '1' or inc_A = '1' ) else
171
                                        '0';
172
 
173
        -- select appropriate alu_output to go to Z depending
174
        -- on control signals
175
        alu_out         <=      carry_out(ALU_WIDTH downto 1)   when
176
                                                ((and_AB = '1' or or_AB = '1') and (sl_AB = '0' and sr_AB = '0')) else
177
                                        shifter_out                                             when
178
                                                (sl_AB = '1' or sr_AB = '1') else
179
                                        adder_out;
180
 
181
        -- selects use of the Adder as an OR gate
182
        adderORsel      <=  '1' when
183
                                                (or_AB = '1') else
184
                                        '0';
185
        -- selects use of the Adder as an XOR gate
186
        -- or as a compare [which uses the XOR function]
187
        adderXORsel     <=      '0' when
188
                                                (xor_AB = '1' or cmp_AB = '1') else
189
                                        '1';
190
 
191
        -- set/unset carry flag depending on relevant conditions
192
        carry           <=  carry_out(carry_out'high)   when
193
                                                (add_AB = '1' and and_AB = '0' and or_AB = '0' and xor_AB = '0' and cpl_B = '0' and clr = '0') else
194
                                        '0'                                              when
195
                                                (and_AB = '1' or  or_AB  = '1' or xor_AB = '1' or cpl_B = '1' or clr = '1') else
196
                                        shifter_carry                           when
197
                                                (sl_AB  = '1' or  sr_AB  = '1');
198
 
199
        -- barrel shifter signals
200
        shifter_direction       <=      '1'     when
201
                                                                (sr_AB = '1') else
202
                                                        '0';
203
 
204
        shifter_inA                     <=      Areg;
205
        shifter_inB                     <=      Breg;
206
 
207
        adder   : alu_adder
208
                port map        (
209
                                        x                       => adder_in_a           ,
210
                                        y                       => adder_in_b           ,
211
                                        carry_in        => carry_in                     ,
212
                                        ORsel           => adderORsel           ,
213
                                        XORsel          => adderXORsel          ,
214
                                        carry_out       => carry_out            ,
215
                                        z                       => adder_out
216
                                        );
217
 
218
        shifter         :       alu_barrel_shifter
219
                port map        (
220
                                        x                       =>      shifter_inA             ,
221
                                        y                       =>      shifter_inB             ,
222
                                        z                       =>      shifter_out             ,
223
                                        c                       =>      shifter_carry   ,
224
                                        direction       =>      shifter_direction
225
                                        );
226
 
227
        registered_ios  :       process (reset, clr, clk, A, B, adder_out, Creg, Zreg, Vreg, load_inputs, load_outputs)
228
                                                begin
229
                                                        if (reset = '1') then
230
                                                                Areg    <=      (others => '0');
231
                                                                Breg    <=      (others => '0');
232
                                                                Yreg    <=      (others => '0');
233
 
234
                                                                Zreg    <=      '1';
235
                                                                Creg    <=      '0';
236
                                                                Vreg    <=      '0';
237
                                                        elsif (clk'event and clk = '1') then
238
                                                                if (load_inputs = '1') then
239
                                                                        Areg    <=      A;
240
                                                                        Breg    <=      B;
241
                                                                end if;
242
                                                                if (load_outputs = '1') then
243
                                                                        Yreg            <= alu_out;
244
                                                                end if;
245
 
246
                                                                -- clear command clears all registers
247
                                                                -- and the carry bit
248
                                                                if (clr = '1') then
249
                                                                        Areg    <=      (others => '0');
250
                                                                        Breg    <=      (others => '0');
251
                                                                        Yreg    <=      (others => '0');
252
 
253
                                                                        Creg    <=      '0';
254
                                                                end if;
255
 
256
 
257
                                                                if (clr_Z = '1') then
258
                                                                        Zreg    <= '0';
259
                                                                end if;
260
                                                                if (clr_C = '1') then
261
                                                                        Creg    <= '0';
262
                                                                end if;
263
                                                                if (clr_V = '1') then
264
                                                                        Vreg    <= '0';
265
                                                                end if;
266
 
267
                                                                -- set the Z register 
268
                                                                if              (alu_out = 0) then
269
                                                                        Zreg    <= '1';
270
                                                                else
271
                                                                        Zreg    <= '0';
272
                                                                end if;
273
 
274
 
275
                                                                Creg    <= carry;
276
                                                        end if;
277
                                                end process registered_ios;
278
 
279
 
280
end behavioural;
281
 
282
 

powered by: WebSVN 2.1.0

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