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

Subversion Repositories mlite

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

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 43 rhoads
-- PROJECT: Plasma CPU core
7 2 rhoads
-- 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 39 rhoads
use work.mlite_pack.all;
15 2 rhoads
 
16
entity alu is
17 47 rhoads
   generic(adder_type : string := "GENERIC");
18 2 rhoads
   port(a_in         : in  std_logic_vector(31 downto 0);
19
        b_in         : in  std_logic_vector(31 downto 0);
20
        alu_function : in  alu_function_type;
21
        c_alu        : out std_logic_vector(31 downto 0));
22
end; --alu
23
 
24
architecture logic of alu is
25
--   type alu_function_type is (alu_nothing, alu_add, alu_subtract, 
26
--      alu_less_than, alu_less_than_signed, alu_equal, alu_not_equal,
27
--      alu_ltz, alu_lez, alu_eqz, alu_nez, alu_gez, alu_gtz,
28
--      alu_or, alu_and, alu_xor, alu_nor);
29 47 rhoads
 
30
   signal aa, bb, sum : std_logic_vector(32 downto 0);
31
   signal do_add      : std_logic;
32 2 rhoads
begin
33
 
34 47 rhoads
alu_proc: process(a_in, b_in, alu_function, sum)
35 2 rhoads
   variable c           : std_logic_vector(31 downto 0);
36
   variable a_eq_b      : std_logic;
37
   variable a_zero      : std_logic;
38
   variable sign_ext    : std_logic;
39
begin
40
   c := ZERO;
41
   if alu_function = alu_add then
42 47 rhoads
          do_add <= '1';
43 2 rhoads
   else
44 47 rhoads
          do_add <= '0';
45 2 rhoads
   end if;
46
   if alu_function = alu_less_than then
47
      sign_ext := '0';
48
   else
49
      sign_ext := '1';
50
   end if;
51 47 rhoads
   aa <= (a_in(31) and sign_ext) & a_in;
52
   bb <= (b_in(31) and sign_ext) & b_in;
53
 
54
   -- Choose bv_adder or lpm_add_sub
55
--   sum <= bv_adder(aa, bb, do_add);
56
--   sum <= bv_adder_lookahead(aa, bb, do_add);
57
 
58 2 rhoads
   if a_in = b_in then
59
      a_eq_b := '1';
60
   else
61
      a_eq_b := '0';
62
   end if;
63
   if a_in = ZERO then
64
      a_zero := '1';
65
   else
66
      a_zero := '0';
67
   end if;
68
   case alu_function is
69
   when alu_add | alu_subtract => --c=a+b
70
      c := sum(31 downto 0);
71
   when alu_less_than =>          --c=a<b
72
      c(0) := sum(32);
73
   when alu_less_than_signed =>   --c=a<b;
74
      c(0) := sum(32);
75
   when alu_equal =>              --c=a==b
76
      c(0) := a_eq_b;
77
   when alu_not_equal =>          --c=a!=b
78
      c(0) := not a_eq_b;
79
   when alu_ltz =>                --c=a<0
80
      c(0) := a_in(31);
81
   when alu_lez =>                --c=a<=0
82
      c(0) := a_in(31) or a_zero;
83
   when alu_eqz =>                --c=a==0
84
      c(0) := a_zero;
85
   when alu_nez =>                --c=a!=0
86
      c(0) := not a_zero;
87
   when alu_gez =>                --c=a>=0
88
      c(0) := not a_in(31);
89
   when alu_gtz =>                --c=a>0
90
      c(0) := not a_zero and not a_in(31);
91
   when alu_or =>                 --c=a|b
92
      c := a_in or b_in;
93
   when alu_and =>                --c=a&b
94
      c := a_in and b_in;
95
   when alu_xor =>                --c=a^b
96
      c := a_in xor b_in;
97
   when alu_nor =>                --c=~(a|b)
98
      c := a_in nor b_in;
99
   when others =>                 --alu_function = alu_nothing
100
      c := ZERO;
101
   end case;
102
 
103 7 rhoads
   c_alu <= c;
104 2 rhoads
end process;
105
 
106 47 rhoads
 
107
   generic_adder:
108
   if adder_type /= "ALTERA" generate
109
      sum <= bv_adder(aa, bb, do_add);
110
   end generate; --generic_adder
111
 
112
   --For Altera
113
   lpm_adder:
114
   if adder_type = "ALTERA" generate
115
      lpm_add_sub_component : lpm_add_sub
116
      GENERIC MAP (
117
         lpm_width => 33,
118
         lpm_direction => "UNUSED",
119
         lpm_type => "LPM_ADD_SUB",
120
         lpm_hint => "ONE_INPUT_IS_CONSTANT=NO"
121
      )
122
      PORT MAP (
123
         dataa => aa,
124
         add_sub => do_add,
125
         datab => bb,
126
         result => sum
127
      );
128
   end generate; --lpm_adder
129
 
130 2 rhoads
end; --architecture logic
131
 

powered by: WebSVN 2.1.0

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