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

Subversion Repositories ion

[/] [ion/] [trunk/] [vhdl/] [mips_alu.vhdl] - Blame information for rev 13

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

Line No. Rev Author Line
1 2 ja_rd
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.std_logic_arith.all;
4
use ieee.std_logic_unsigned.all;
5
 
6
use work.mips_pkg.all;
7
 
8
entity mips_alu is
9
    port(
10
        clk             : in std_logic;
11
        reset           : in std_logic;
12
 
13
        -- function selection
14
        ac              : in t_alu_control;
15
 
16
        flags           : out t_alu_flags;
17
 
18
        -- '1' when inp1 is zero
19
        --flags.inp1_eq_zero    : out std_logic;
20
        -- '1' when inp1 is < 0 (bit 31 set)
21
        --flags.inp1_lt_zero    : out std_logic;
22
        -- '1' when (inp1 + ac.neg_sel(inp2) + ac.cy_in) < 0
23
        --flags.inp1_lt_inp2    : out std_logic;
24
        -- '1' when (inp1 + ac.neg_sel(inp2) + ac.cy_in) == 0
25
        --flags.inp1_eq_inp2    : out std_logic;
26
 
27
        -- data inputs
28
        inp1            : in std_logic_vector(31 downto 0);
29
        inp2            : in std_logic_vector(31 downto 0);
30
        -- data result output
31
        outp            : out std_logic_vector(31 downto 0)
32
    );
33
end;
34
 
35
architecture rtl of mips_alu is
36
 
37
subtype t_eword is std_logic_vector(32 downto 0);
38
 
39
signal inp2_neg :           t_word;
40
signal alu_eop1, alu_eop2 : t_eword;
41
signal sex1, sex2 :         std_logic;
42
signal alu_arith :          t_eword;
43
signal alu_shift :          t_word;
44
signal alu_logic_shift :    t_word;
45
signal alu_logic :          t_word;
46
 
47
signal less_than_zero :     std_logic;
48
signal final_mux_sel :      std_logic_vector(1 downto 0);
49
signal alu_temp :           t_word;
50
 
51
 
52
 
53
begin
54
 
55
 
56
with ac.neg_sel select inp2_neg <=
57
    not inp2                        when "01",      -- nor, sub, etc.
58
    inp2(15 downto 0) & X"0000"     when "10",      -- lhi
59
    X"00000000"                     when "11",      -- zero
60
    inp2                            when others;    -- straight
61
 
62
sex1 <= inp1(31) when ac.arith_unsigned='0' else '0';
63
alu_eop1 <= sex1 & inp1;
64
sex2 <= inp2_neg(31) when ac.arith_unsigned='0' else '0';
65
alu_eop2 <= sex2 & inp2_neg;
66
alu_arith <= alu_eop1 + alu_eop2 + ac.cy_in;
67
 
68
with ac.logic_sel select alu_logic <=
69
    inp1 and inp2_neg       when "00",
70
    inp1 or  inp2_neg       when "01",
71
    inp1 xor inp2_neg       when "10",
72
             inp2_neg       when others;
73
 
74
shifter : entity work.mips_shifter
75
    port map (
76
        d   => inp2,
77
        a   => ac.shift_amount,
78
        fn  => ac.shift_sel,
79
        r   => alu_shift
80
    );
81
 
82
 
83
with ac.use_logic select alu_logic_shift <=
84
    alu_logic           when "01",
85
    not alu_logic       when "11",  -- used only by NOR instruction
86
    alu_shift           when others;
87
 
88
 
89
final_mux_sel(0) <= ac.use_arith when ac.use_slt='0' else less_than_zero;
90
final_mux_sel(1) <= ac.use_slt;
91
 
92
with final_mux_sel select alu_temp <=
93
    alu_arith(31 downto 0)  when "01",
94
    alu_logic_shift         when "00",
95
    X"00000001"             when "11",
96
    X"00000000"             when others;
97
 
98
less_than_zero <= alu_arith(32);
99
 
100
flags.inp1_lt_zero <= inp1(31);
101
flags.inp1_lt_inp2 <= less_than_zero;
102
flags.inp1_eq_inp2 <= '1' when alu_arith(31 downto 0)=X"00000000" else '0';
103
flags.inp1_eq_zero <= '1' when inp1(31 downto 0)=X"00000000" else '0'; -- FIXME simplify
104
 
105
outp <= alu_temp;
106
 
107
end; --architecture rtl

powered by: WebSVN 2.1.0

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