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

Subversion Repositories ion

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

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

Line No. Rev Author Line
1 161 ja_rd
--------------------------------------------------------------------------------
2
-- mips_alu.vhdl -- integer arithmetic ALU, excluding mult/div functionality.
3
--
4
--------------------------------------------------------------------------------
5 162 ja_rd
-- Copyright (C) 2011 Jose A. Ruiz
6 161 ja_rd
--                                                              
7
-- This source file may be used and distributed without         
8
-- restriction provided that this copyright statement is not    
9
-- removed from the file and that any derivative work contains  
10
-- the original copyright notice and the associated disclaimer. 
11
--                                                              
12
-- This source file is free software; you can redistribute it   
13
-- and/or modify it under the terms of the GNU Lesser General   
14
-- Public License as published by the Free Software Foundation; 
15
-- either version 2.1 of the License, or (at your option) any   
16
-- later version.                                               
17
--                                                              
18
-- This source is distributed in the hope that it will be       
19
-- useful, but WITHOUT ANY WARRANTY; without even the implied   
20
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      
21
-- PURPOSE.  See the GNU Lesser General Public License for more 
22
-- details.                                                     
23
--                                                              
24
-- You should have received a copy of the GNU Lesser General    
25
-- Public License along with this source; if not, download it   
26
-- from http://www.opencores.org/lgpl.shtml
27
--------------------------------------------------------------------------------
28
 
29 2 ja_rd
library ieee;
30
use ieee.std_logic_1164.all;
31
use ieee.std_logic_arith.all;
32
use ieee.std_logic_unsigned.all;
33
 
34
use work.mips_pkg.all;
35
 
36
entity mips_alu is
37
    port(
38
        clk             : in std_logic;
39
        reset           : in std_logic;
40
 
41
        -- function selection
42
        ac              : in t_alu_control;
43 161 ja_rd
        -- comparison result flags
44
        flags           : out t_alu_flags;
45 2 ja_rd
        -- data inputs
46
        inp1            : in std_logic_vector(31 downto 0);
47
        inp2            : in std_logic_vector(31 downto 0);
48
        -- data result output
49
        outp            : out std_logic_vector(31 downto 0)
50
    );
51
end;
52
 
53
architecture rtl of mips_alu is
54
 
55
subtype t_eword is std_logic_vector(32 downto 0);
56
 
57
signal inp2_neg :           t_word;
58
signal alu_eop1, alu_eop2 : t_eword;
59
signal sex1, sex2 :         std_logic;
60
signal alu_arith :          t_eword;
61
signal alu_shift :          t_word;
62
signal alu_logic_shift :    t_word;
63
signal alu_logic :          t_word;
64
 
65
signal less_than_zero :     std_logic;
66
signal final_mux_sel :      std_logic_vector(1 downto 0);
67
signal alu_temp :           t_word;
68
 
69
 
70
 
71
begin
72
 
73
 
74
with ac.neg_sel select inp2_neg <=
75
    not inp2                        when "01",      -- nor, sub, etc.
76
    inp2(15 downto 0) & X"0000"     when "10",      -- lhi
77
    X"00000000"                     when "11",      -- zero
78
    inp2                            when others;    -- straight
79
 
80
sex1 <= inp1(31) when ac.arith_unsigned='0' else '0';
81
alu_eop1 <= sex1 & inp1;
82 82 ja_rd
sex2 <= inp2_neg(31) when (ac.arith_unsigned='0' or ac.use_slt='1') else '0';
83 2 ja_rd
alu_eop2 <= sex2 & inp2_neg;
84
alu_arith <= alu_eop1 + alu_eop2 + ac.cy_in;
85
 
86
with ac.logic_sel select alu_logic <=
87
    inp1 and inp2_neg       when "00",
88
    inp1 or  inp2_neg       when "01",
89
    inp1 xor inp2_neg       when "10",
90
             inp2_neg       when others;
91
 
92
shifter : entity work.mips_shifter
93
    port map (
94
        d   => inp2,
95
        a   => ac.shift_amount,
96
        fn  => ac.shift_sel,
97
        r   => alu_shift
98
    );
99
 
100
 
101
with ac.use_logic select alu_logic_shift <=
102
    alu_logic           when "01",
103
    not alu_logic       when "11",  -- used only by NOR instruction
104
    alu_shift           when others;
105
 
106
 
107
final_mux_sel(0) <= ac.use_arith when ac.use_slt='0' else less_than_zero;
108
final_mux_sel(1) <= ac.use_slt;
109
 
110
with final_mux_sel select alu_temp <=
111
    alu_arith(31 downto 0)  when "01",
112
    alu_logic_shift         when "00",
113
    X"00000001"             when "11",
114
    X"00000000"             when others;
115
 
116
less_than_zero <= alu_arith(32);
117
 
118
flags.inp1_lt_zero <= inp1(31);
119
flags.inp1_lt_inp2 <= less_than_zero;
120
flags.inp1_eq_inp2 <= '1' when alu_arith(31 downto 0)=X"00000000" else '0';
121
flags.inp1_eq_zero <= '1' when inp1(31 downto 0)=X"00000000" else '0'; -- FIXME simplify
122
 
123
outp <= alu_temp;
124
 
125
end; --architecture rtl

powered by: WebSVN 2.1.0

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