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

Subversion Repositories mlite

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

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 81 rhoads
--      alu_less_than, alu_less_than_signed, 
27 2 rhoads
--      alu_or, alu_and, alu_xor, alu_nor);
28 47 rhoads
   signal aa, bb, sum : std_logic_vector(32 downto 0);
29
   signal do_add      : std_logic;
30 2 rhoads
begin
31
 
32 47 rhoads
alu_proc: process(a_in, b_in, alu_function, sum)
33 81 rhoads
   variable sign_ext  : std_logic;
34 2 rhoads
begin
35
   if alu_function = alu_add then
36 81 rhoads
      do_add <= '1';
37 2 rhoads
   else
38 81 rhoads
      do_add <= '0';
39 2 rhoads
   end if;
40
   if alu_function = alu_less_than then
41
      sign_ext := '0';
42
   else
43
      sign_ext := '1';
44
   end if;
45 47 rhoads
   aa <= (a_in(31) and sign_ext) & a_in;
46
   bb <= (b_in(31) and sign_ext) & b_in;
47
 
48 2 rhoads
   case alu_function is
49
   when alu_add | alu_subtract => --c=a+b
50 81 rhoads
      c_alu <= sum(31 downto 0);
51 2 rhoads
   when alu_less_than =>          --c=a<b
52 81 rhoads
      c_alu <= ZERO(31 downto 1) & sum(32);
53 2 rhoads
   when alu_less_than_signed =>   --c=a<b;
54 81 rhoads
      c_alu <= ZERO(31 downto 1) & sum(32);
55 2 rhoads
   when alu_or =>                 --c=a|b
56 81 rhoads
      c_alu <= a_in or b_in;
57 2 rhoads
   when alu_and =>                --c=a&b
58 81 rhoads
      c_alu <= a_in and b_in;
59 2 rhoads
   when alu_xor =>                --c=a^b
60 81 rhoads
      c_alu <= a_in xor b_in;
61 2 rhoads
   when alu_nor =>                --c=~(a|b)
62 81 rhoads
      c_alu <= a_in nor b_in;
63 2 rhoads
   when others =>                 --alu_function = alu_nothing
64 81 rhoads
      c_alu <= ZERO;
65 2 rhoads
   end case;
66
 
67
end process;
68
 
69 47 rhoads
 
70
   generic_adder:
71
   if adder_type /= "ALTERA" generate
72
      sum <= bv_adder(aa, bb, do_add);
73
   end generate; --generic_adder
74
 
75
   --For Altera
76
   lpm_adder:
77
   if adder_type = "ALTERA" generate
78
      lpm_add_sub_component : lpm_add_sub
79
      GENERIC MAP (
80
         lpm_width => 33,
81
         lpm_direction => "UNUSED",
82
         lpm_type => "LPM_ADD_SUB",
83
         lpm_hint => "ONE_INPUT_IS_CONSTANT=NO"
84
      )
85
      PORT MAP (
86
         dataa => aa,
87
         add_sub => do_add,
88
         datab => bb,
89
         result => sum
90
      );
91
   end generate; --lpm_adder
92
 
93 2 rhoads
end; --architecture logic
94
 

powered by: WebSVN 2.1.0

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