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

Subversion Repositories copyblaze

[/] [copyblaze/] [trunk/] [copyblaze/] [rtl/] [vhdl/] [cpu/] [cp_Alu.vhd] - Blame information for rev 71

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ameziti
--------------------------------------------------------------------------------
2
-- Company: 
3
--
4
-- File: cp_Alu.vhd
5
--
6
-- Description:
7
--      projet copyblaze
8
--      Arithmetic, Logic, Shift, Rotate
9
--
10
-- File history:
11
-- v1.0: 07/10/11: Creation
12
--
13
-- Targeted device: ProAsic A3P250 VQFP100
14
-- Author: AbdAllah Meziti
15
--------------------------------------------------------------------------------
16
 
17
library ieee;
18
use ieee.std_logic_1164.all;
19
use ieee.numeric_std.all;
20
 
21
use     work.Usefull_Pkg.all;           -- Usefull Package
22
 
23
--------------------------------------------------------------------------------
24
-- Entity: cp_Alu
25
--
26
-- Description:
27
--      
28
--      REMARQUE:
29
--
30
--      
31
-- History:
32
-- 07/10/11 AM: Creation
33
-- ---------------------
34
-- xx/xx/xx AM: 
35
--                              
36
--------------------------------------------------------------------------------
37
entity cp_Alu is
38
        generic
39
        (
40
                GEN_WIDTH_DATA          : positive := 8
41
        );
42
        port (
43
        --------------------------------------------------------------------------------
44
        -- Signaux Fonctionels
45
        --------------------------------------------------------------------------------
46
                OperationSelect_i       : in std_ulogic_vector(2 downto 0);
47
 
48
                LogicOper_i                     : in std_ulogic_vector(1 downto 0);
49
                ArithOper_i                     : in std_ulogic_vector(1 downto 0);
50
 
51
                OperandSelect_i         : in std_ulogic;
52
 
53
                CY_i                            : in std_ulogic;
54
                sX_i                            : in std_ulogic_vector(GEN_WIDTH_DATA-1 downto 0);       -- 
55
                sY_i                            : in std_ulogic_vector(GEN_WIDTH_DATA-1 downto 0);       -- 
56
                kk_i                            : in std_ulogic_vector(GEN_WIDTH_DATA-1 downto 0);       -- 
57
 
58
                ShiftBit_i                      : in std_ulogic_vector( 2 downto 0 );
59
                ShiftSens_i                     : in std_ulogic;
60
 
61
                Result_o                        : out std_ulogic_vector(GEN_WIDTH_DATA-1 downto 0);      -- 
62
                C_o                                     : out std_ulogic;
63
                Z_o                                     : out std_ulogic
64
        );
65
end cp_Alu;
66
 
67
--------------------------------------------------------------------------------
68
-- Architecture: RTL
69
-- of entity : cp_Alu
70
--------------------------------------------------------------------------------
71
architecture rtl of cp_Alu is
72
 
73
        --------------------------------------------------------------------------------
74
        -- Définition des fonctions
75
        --------------------------------------------------------------------------------
76
 
77
 
78
 
79
        --------------------------------------------------------------------------------
80
        -- Définition des constantes
81
        --------------------------------------------------------------------------------
82
 
83
        --------------------------------------------------------------------------------
84
        -- Définition des signaux interne
85
        --------------------------------------------------------------------------------
86
                signal          iOperand1               : std_ulogic_vector(GEN_WIDTH_DATA-1 downto 0);
87
                signal          iOperand2               : std_ulogic_vector(GEN_WIDTH_DATA-1 downto 0);
88
 
89
                signal          iOperand1Arith  : std_ulogic_vector(GEN_WIDTH_DATA downto 0);
90
                signal          iOperand2Arith  : std_ulogic_vector(GEN_WIDTH_DATA downto 0);
91
 
92
                signal          iShiftResult    : std_ulogic_vector(GEN_WIDTH_DATA-1 downto 0);
93
                signal          iLogicalResult  : std_ulogic_vector(GEN_WIDTH_DATA-1 downto 0);
94
                signal          iArithResult    : std_ulogic_vector(GEN_WIDTH_DATA downto 0);
95
 
96
                signal          iTotalResult    : std_ulogic_vector(GEN_WIDTH_DATA-1 downto 0);
97
 
98
                signal          iShiftBit               : std_ulogic;
99
 
100
                signal          iShiftC                 : std_ulogic;
101
                signal          iLogicC                 : std_ulogic;
102
                signal          iArithC                 : std_ulogic;
103
                signal          iArithCin               : std_ulogic;
104
 
105
        --------------------------------------------------------------------------------
106
        -- Déclaration des composants
107
        --------------------------------------------------------------------------------
108
        component cp_CLAAdder
109
                generic
110
                (
111
                        GEN_WIDTH_DATA          : positive := 8
112
                );
113
                port (
114
                --------------------------------------------------------------------------------
115
                -- Signaux Fonctionels
116
                --------------------------------------------------------------------------------
117
                        CarryIn_i                       : in std_ulogic;
118
                        sX_i                            : in std_ulogic_vector(GEN_WIDTH_DATA-1 downto 0);
119
                        sY_i                            : in std_ulogic_vector(GEN_WIDTH_DATA-1 downto 0);
120
 
121
                        CarryOut_o                      : out std_ulogic;
122
                        Result_o                        : out std_ulogic_vector(GEN_WIDTH_DATA-1 downto 0)
123
                );
124
        end component;
125
 
126
begin
127
 
128
        iOperand1       <=      sX_i;
129
        iOperand2       <=      sY_i    when ( OperandSelect_i = '1' ) else
130
                                        kk_i;
131
 
132
 
133
        --------------------------------------------------------------------------------
134
        -- Operation de décalage et rotation
135
        --------------------------------------------------------------------------------
136
        with ShiftBit_i select
137
                iShiftBit       <=
138
                                                        ('0')                                            when    "110",
139
                                                        ('1')                                           when    "111",
140
                                                        (CY_i)                                          when    "000",
141
                                                        iOperand1(GEN_WIDTH_DATA-1)     when    "010",
142
                                                        iOperand1(0)                             when    "100",
143
 
144
                                                        '0'                                                      when    others;
145
 
146
        with ShiftSens_i select
147
                iShiftResult    <=
148
                                                        iOperand1(GEN_WIDTH_DATA-2 downto 0) & iShiftBit when    '0',     --      Left
149
                                                        iShiftBit & iOperand1(GEN_WIDTH_DATA-1 downto 1)        when    '1',    --      Right
150
                                                        iOperand1                                                                                       when    others;
151
        with ShiftSens_i select
152
                iShiftC                 <=
153
                                                        iOperand1(GEN_WIDTH_DATA-1)     when    '0',     --      Left
154
                                                        iOperand1(0)                             when    '1',    --      Right
155
                                                        '0'                                                      when    others;
156
 
157
        --------------------------------------------------------------------------------
158
        -- Operation Logique
159
        --------------------------------------------------------------------------------
160
        with LogicOper_i select
161
                iLogicalResult  <=
162
                                                                                        iOperand2       when    "00",
163
                                                        iOperand1       and     iOperand2       when    "01",
164
                                                        iOperand1       or      iOperand2       when    "10",
165
                                                        iOperand1       xor     iOperand2       when    "11",
166
                                                        iOperand1                                       when    others;
167
 
168
        iLogicC                         <=      ODD_Func(iLogicalResult);
169
        --------------------------------------------------------------------------------
170
        -- Operation Arithmetique
171
        --------------------------------------------------------------------------------
172
        -- Instruction  | #ADD/SUB      | Include CY    | Cin
173
        --      ADD                     |       0                |       0                        |       0
174
        --      ADDCY           |       0                |       1                       |       CY
175
        --      SUB                     |       1               |       0                        |       1
176
        --      SUBCY           |       1               |       1                       |       not CY
177
        with ArithOper_i select
178
                iArithCin       <=
179
                                                        ('0')    when    "00", -- ADD
180
                                                        (CY_i)  when    "01", -- ADDCY
181
                                                        ('1')   when    "10", -- SUB
182
                                                 not(CY_i)      when    "11", -- SUBCY
183
 
184
                                                        ('0')    when    others;
185
 
186
        iOperand1Arith  <=      '0' & iOperand1;
187
        -- A SUB B => A ADD (not(B) + 1)
188
        iOperand2Arith  <=      not('0' & iOperand2)     when (ArithOper_i(1)='1') else ('0' & iOperand2);
189
 
190
        U_Adder : cp_CLAAdder
191
                generic map
192
                (
193
                        GEN_WIDTH_DATA          => GEN_WIDTH_DATA+1
194
                )
195
                port map(
196
                --------------------------------------------------------------------------------
197
                -- Signaux Fonctionels
198
                --------------------------------------------------------------------------------
199
                        CarryIn_i                       => iArithCin            ,
200
                        sX_i                            => iOperand1Arith       ,
201
                        sY_i                            => iOperand2Arith       ,
202
 
203
                        CarryOut_o                      => open                         ,
204
                        Result_o                        => iArithResult
205
                );
206
 
207
        iArithC                 <=      iArithResult(GEN_WIDTH_DATA);
208
 
209
        --------------------------------------------------------------------------------
210
        -- Choix de l'operation
211
        --------------------------------------------------------------------------------
212
        with OperationSelect_i select
213
                iTotalResult    <=
214
                                                        iShiftResult                                            when    "000",
215
                                                        iLogicalResult                                          when    "001",
216
                                                        iArithResult(iTotalResult'range)        when    "010",
217
                                                        iOperand2                                                       when    "011",
218
 
219
                                                        iOperand1                                                       when    others;
220
 
221
        --------------------------------------------------------------------------------
222
        -- Resultats et Flags
223
        --------------------------------------------------------------------------------
224
        Result_o        <=      iTotalResult;
225
        Z_o                     <=      not ( OR_Func( iTotalResult ) );
226
 
227
        with OperationSelect_i select
228
                C_o             <=
229
                                        iShiftC                                 when    "000",  -- (Shift/Rotate)               : 
230
                                        iLogicC                                 when    "001",  -- (Test)                               : Odd parity
231
                                        iArithC                                 when    others; -- (Add/Sub/Compare)    : Carry, Borrow
232
 
233
end rtl;
234
 

powered by: WebSVN 2.1.0

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