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

Subversion Repositories diogenes

[/] [diogenes/] [tags/] [initial/] [vhdl/] [cpu/] [alu.vhd] - Blame information for rev 236

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 154 fellnhofer
----------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer: 
4
-- 
5
-- Create Date:    13:14:05 02/11/2007 
6
-- Design Name: 
7
-- Module Name:    alu - Behavioral 
8
-- Project Name: 
9
-- Target Devices: 
10
-- Tool versions: 
11
-- Description: 
12
--
13
-- Dependencies: 
14
--
15
-- Revision: 
16
-- Revision 0.01 - File Created
17
-- Additional Comments: 
18
--
19
----------------------------------------------------------------------------------
20
library IEEE;
21
use IEEE.STD_LOGIC_1164.ALL;
22
use IEEE.STD_LOGIC_ARITH.ALL;
23
use IEEE.STD_LOGIC_UNSIGNED.ALL;
24
 
25
use work.types.all;
26
 
27
---- Uncomment the following library declaration if instantiating
28
---- any Xilinx primitives in this code.
29
--library UNISIM;
30
--use UNISIM.VComponents.all;
31
 
32
entity alu is
33
        port (
34
                clk: IN std_logic;
35
                reset: in std_logic;
36
                alu_op : in std_logic_VECTOR(10 downto 0);
37
                a: IN slv_32;
38
                b: IN slv_32;
39
                s: OUT slv_32
40
        );
41
end alu;
42
 
43
 
44
 
45
architecture Behavioral of alu is
46
 
47
component barrel is
48
        port (
49
                --clk: IN std_logic;
50
                --reset: in std_logic;
51
                a: IN slv_32;
52
                b: IN std_logic_vector(5 downto 0);
53
                s: OUT slv_32
54
        );
55
end component;
56
 
57
 
58
signal aa: unsigned(31 downto 0);
59
signal bb: unsigned(31 downto 0);
60
 
61
signal shift_result: slv_32;
62
signal shift_in: std_logic_vector(5 downto 0);
63
 
64
 
65
 
66
begin
67
 
68
        shift_in(5) <= b(31);
69
        shift_in(4 downto 0) <= b(4 downto 0);
70
        cbarrel: barrel
71
        port map( a => a, b => shift_in, s => shift_result);
72
 
73
 
74
 
75
        aa(31 downto 0) <= unsigned(a);
76
        bb(31 downto 0) <= unsigned(b);
77
 
78
        process (clk, reset)
79
                variable te: unsigned(31 downto 0) := (others => '0');
80
        begin
81
 
82
                if(reset='0') then
83
                        s <= (others => '0');
84
                elsif(rising_edge(clk)) then
85
 
86
                        case alu_op is
87
                                when "00000000001" =>
88
                                        te := aa + bb;
89
                                        s <= std_logic_vector(te);
90
                                when "00000000010" =>
91
                                        te := aa - bb;
92
                                        s <= std_logic_vector(te);
93
                                when "00000000100" =>
94
                                        s <= a and b;
95
                                when "00000001000" =>
96
                                        s <= a or b;
97
                                when "00000010000" =>
98
                                        s <= a xor b;
99
                                when "00000100000" =>
100
                                        s <= shift_result;   -- shift
101
                                when "00001000000" =>
102
                                        if unsigned(a) < unsigned(b) then
103
                                                s <= (0 => '1', others => '0');
104
                                        else
105
                                                s <= (others => '0');
106
                                        end if;
107
                                when "00010000000" =>
108
                                        if signed(a) < signed(b) then
109
                                                s <= (0 => '1', others => '0');
110
                                        else
111
                                                s <= (others => '0');
112
                                        end if;
113
                                when "00100000000" =>
114
                                        s <= b;
115
                                when "01000000000" =>
116
                                        s <= (others => 'X');
117
                                when "10000000000" =>
118
                                        s <= (others => 'X');
119
                                when others =>
120
                                        s <= (others => 'X');
121
                        end case;
122
                end if;
123
        end process;
124
end Behavioral;
125
 

powered by: WebSVN 2.1.0

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