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

Subversion Repositories hicovec

[/] [hicovec/] [trunk/] [cpu/] [units/] [alu.vhd] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 hmanske
------------------------------------------------------------------
2 4 hmanske
-- PROJECT:      HiCoVec (highly configurable vector processor)
3 2 hmanske
--
4
-- ENTITY:      alu
5
--
6
-- PURPOSE:     alu of scalar unit
7
--
8
-- AUTHOR:      harald manske, haraldmanske@gmx.de
9
--
10
-- VERSION:     1.0
11
-----------------------------------------------------------------
12
library ieee;
13
use ieee.std_logic_1164.all;
14
use ieee.std_logic_arith.all;
15
use ieee.numeric_std.all;
16
 
17
use work.cfg.all;
18
 
19
entity alu is
20
    port(
21
        a_in:       in std_logic_vector(31 downto 0);
22
        b_in:       in std_logic_vector(31 downto 0);
23
        carry_in:   in std_logic;
24
        aluop:      in std_logic_vector(3 downto 0);
25
        op_select:  in std_logic;
26
        zero_out:   out std_logic;
27
        carry_out:  out std_logic;
28
        alu_out:    out std_logic_vector(31 downto 0)
29
    );
30
end alu;
31
 
32
architecture rtl of alu is
33
    component multiplexer2
34
        generic (
35
            w : positive
36
        );
37
        port (
38
            selector:   in std_logic;
39
            data_in_0:  in std_logic_vector(w-1 downto 0);
40
            data_in_1:  in std_logic_vector(w-1 downto 0);
41
            data_out:   out std_logic_vector(w-1 downto 0)
42
        );
43
    end component;
44
 
45
    for mux: multiplexer2 use entity work.multiplexer2(rtl);
46
 
47
    signal aluop_multiplexed: std_logic_vector(3 downto 0) := "0000";
48
 
49
    signal left:            unsigned(32 downto 0);
50
    signal right:           unsigned(32 downto 0);
51
    signal mult_res:        unsigned(31 downto 0);
52
    signal carry:           std_logic;
53
 
54
begin
55
    mux: multiplexer2
56
            generic map (w => 4)
57
            port map (selector => op_select, data_in_0 => aluop, data_in_1 => "0000",
58
              data_out => aluop_multiplexed);
59
 
60
    process (a_in, b_in, carry, left, right, aluop_multiplexed, mult_res)
61
        variable alu_out_buffer:  unsigned(32 downto 0);
62
    begin
63
        case aluop_multiplexed is
64
            when  "0000" | "0001" | "0100" =>    -- add / adc / inc - use same adder  
65
                alu_out_buffer := left + right + carry;
66
 
67
            when  "0010" | "0011" | "0110" =>    -- sub / sbc / dec - use same subtractor  
68
                alu_out_buffer := left - right - carry;
69
 
70
            when  "1000" =>      -- and (a and b) 
71
                alu_out_buffer := "0" & unsigned( a_in and b_in);
72
 
73
            when  "1001" =>      -- or  (a or b)
74
                alu_out_buffer := "0" & unsigned(a_in or b_in);
75
 
76
            when  "1010" =>      -- xor (a xor b)
77
                alu_out_buffer := "0" & unsigned(a_in xor b_in);
78
 
79
            when "1011" =>   -- mult (a(15:0) * b(15:0)
80
                alu_out_buffer := "0" & mult_res;
81
 
82
            when  "1100" =>      -- lsl (a shift left, insert 0) 
83
                alu_out_buffer(32 downto 1) := left(31 downto 0);
84
                alu_out_buffer(0) := '0';
85
 
86
            when  "1110" =>      -- lsr (a shift right, insert 0)
87
                alu_out_buffer(32) := left(0);
88
                alu_out_buffer(30 downto 0) := left(31 downto 1);
89
                alu_out_buffer(31) := '0';
90
 
91
            when  "1101" =>      -- rol (a shift left, insert c)
92
                alu_out_buffer(32 downto 1) := left(31 downto 0);
93
                alu_out_buffer(0) := carry;
94
 
95
            when  "1111" =>      -- ror (a shift right, insert c)
96
                alu_out_buffer(32) := left(0);
97
                alu_out_buffer(30 downto 0) := left(31 downto 1);
98
                alu_out_buffer(31) := carry;
99
 
100
            when others =>       -- not defined
101
                alu_out_buffer := (others => '0');
102
        end case;
103
 
104
        alu_out <= std_logic_vector(alu_out_buffer(31 downto 0));
105
        carry_out <= alu_out_buffer(32);
106
 
107
        if(alu_out_buffer(31 downto 0) = 0) then
108
             zero_out <= '1';
109
        else
110
             zero_out <= '0';
111
        end if;
112
    end process;
113
 
114
    left <= unsigned ("0" & a_in);
115
 
116
    right <= (others => '0') when (aluop_multiplexed = "0100" or aluop_multiplexed = "0110")
117
        else unsigned ("0" & b_in);
118
 
119
    carry <= '0' when (aluop_multiplexed = "0000" or aluop_multiplexed = "0010")
120
        else '1' when (aluop_multiplexed = "0100" or aluop_multiplexed = "0110")
121
        else carry_in;
122
 
123
    mult_gen: if use_scalar_mult generate
124
        mult_res <= left(15 downto 0) * right(15 downto 0);
125
    end generate;
126
 
127
    not_mult_gen: if not use_scalar_mult generate
128
        mult_res <= (others => '0');
129
    end generate;
130
end rtl;
131
 

powered by: WebSVN 2.1.0

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