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

Subversion Repositories mlite

[/] [mlite/] [trunk/] [vhdl/] [alu.vhd] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 rhoads
---------------------------------------------------------------------
2
-- TITLE: Arithmetic Logic Unit
3
-- AUTHOR: Steve Rhoads (rhoadss@yahoo.com)
4
-- DATE CREATED: 2/8/01
5
-- FILENAME: alu.vhd
6
-- PROJECT: MIPS CPU core
7
-- COPYRIGHT: Software placed into the public domain by the author.
8
--    Software 'as is' without warranty.  Author liable for nothing.
9
-- DESCRIPTION:
10
--    Implements the ALU.
11
---------------------------------------------------------------------
12
library ieee;
13
use ieee.std_logic_1164.all;
14
use work.mips_pack.all;
15
 
16
entity alu is
17
   port(a_in         : in  std_logic_vector(31 downto 0);
18
        b_in         : in  std_logic_vector(31 downto 0);
19
        alu_function : in  alu_function_type;
20
        c_alu        : out std_logic_vector(31 downto 0));
21
end; --alu
22
 
23
architecture logic of alu is
24
--   type alu_function_type is (alu_nothing, alu_add, alu_subtract, 
25
--      alu_less_than, alu_less_than_signed, alu_equal, alu_not_equal,
26
--      alu_ltz, alu_lez, alu_eqz, alu_nez, alu_gez, alu_gtz,
27
--      alu_or, alu_and, alu_xor, alu_nor);
28
begin
29
 
30
alu_proc: process(a_in, b_in, alu_function)
31
   variable c           : std_logic_vector(31 downto 0);
32
   variable aa, bb, sum : std_logic_vector(32 downto 0);
33
   variable do_sub      : std_logic;
34
   variable a_eq_b      : std_logic;
35
   variable a_zero      : std_logic;
36
   variable sign_ext    : std_logic;
37
begin
38
   c := ZERO;
39
   if alu_function = alu_add then
40
      do_sub := '0';
41
   else
42
      do_sub := '1';
43
   end if;
44
   if alu_function = alu_less_than then
45
      sign_ext := '0';
46
   else
47
      sign_ext := '1';
48
   end if;
49
   aa := (a_in(31) and sign_ext) & a_in;
50
   bb := (b_in(31) and sign_ext) & b_in;
51
   sum := bv_adder(aa, bb, do_sub);
52
--   sum := bv_adder_lookahead(aa, bb, do_sub);
53
   if a_in = b_in then
54
      a_eq_b := '1';
55
   else
56
      a_eq_b := '0';
57
   end if;
58
   if a_in = ZERO then
59
      a_zero := '1';
60
   else
61
      a_zero := '0';
62
   end if;
63
   case alu_function is
64
   when alu_add | alu_subtract => --c=a+b
65
      c := sum(31 downto 0);
66
   when alu_less_than =>          --c=a<b
67
      c(0) := sum(32);
68
   when alu_less_than_signed =>   --c=a<b;
69
      c(0) := sum(32);
70
   when alu_equal =>              --c=a==b
71
      c(0) := a_eq_b;
72
   when alu_not_equal =>          --c=a!=b
73
      c(0) := not a_eq_b;
74
   when alu_ltz =>                --c=a<0
75
      c(0) := a_in(31);
76
   when alu_lez =>                --c=a<=0
77
      c(0) := a_in(31) or a_zero;
78
   when alu_eqz =>                --c=a==0
79
      c(0) := a_zero;
80
   when alu_nez =>                --c=a!=0
81
      c(0) := not a_zero;
82
   when alu_gez =>                --c=a>=0
83
      c(0) := not a_in(31);
84
   when alu_gtz =>                --c=a>0
85
      c(0) := not a_zero and not a_in(31);
86
   when alu_or =>                 --c=a|b
87
      c := a_in or b_in;
88
   when alu_and =>                --c=a&b
89
      c := a_in and b_in;
90
   when alu_xor =>                --c=a^b
91
      c := a_in xor b_in;
92
   when alu_nor =>                --c=~(a|b)
93
      c := a_in nor b_in;
94
   when others =>                 --alu_function = alu_nothing
95
      c := ZERO;
96
   end case;
97
 
98
--   if alu_function = alu_nothing then
99
--      c_alu <= "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ";
100
--   else
101
      c_alu <= c;
102
--   end if;
103
end process;
104
 
105
end; --architecture logic
106
 

powered by: WebSVN 2.1.0

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