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

Subversion Repositories mlite

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

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 112 rhoads
   generic(adder_type : string := "GENERIC";
18
           alu_type   : string := "GENERIC");
19 2 rhoads
   port(a_in         : in  std_logic_vector(31 downto 0);
20
        b_in         : in  std_logic_vector(31 downto 0);
21
        alu_function : in  alu_function_type;
22
        c_alu        : out std_logic_vector(31 downto 0));
23
end; --alu
24
 
25
architecture logic of alu is
26
--   type alu_function_type is (alu_nothing, alu_add, alu_subtract, 
27 81 rhoads
--      alu_less_than, alu_less_than_signed, 
28 2 rhoads
--      alu_or, alu_and, alu_xor, alu_nor);
29 112 rhoads
 
30 47 rhoads
   signal aa, bb, sum : std_logic_vector(32 downto 0);
31
   signal do_add      : std_logic;
32 112 rhoads
   signal sign_ext    : std_logic;
33 2 rhoads
begin
34
 
35 112 rhoads
   do_add <= '1' when alu_function = alu_add else '0';
36
   sign_ext <= '0' when alu_function = alu_less_than else '1';
37 47 rhoads
   aa <= (a_in(31) and sign_ext) & a_in;
38
   bb <= (b_in(31) and sign_ext) & b_in;
39
 
40 112 rhoads
   -- synthesis translate_off
41
   GENERIC_ALU: if alu_type="GENERIC" generate
42
   -- synthesis translate_on
43 2 rhoads
 
44 112 rhoads
      c_alu <= sum(31 downto 0) when alu_function=alu_add or alu_function=alu_subtract else
45
               ZERO(31 downto 1) & sum(32) when alu_function=alu_less_than or alu_function=alu_less_than_signed else
46
               a_in or  b_in    when alu_function=alu_or else
47
               a_in and b_in    when alu_function=alu_and else
48
               a_in xor b_in    when alu_function=alu_xor else
49
               a_in nor b_in    when alu_function=alu_nor else
50
               ZERO;
51 2 rhoads
 
52 112 rhoads
   -- synthesis translate_off
53
   end generate;
54
   -- synthesis translate_on
55 47 rhoads
 
56 112 rhoads
   -- synopsys synthesis_off
57
 
58
   AREA_OPTIMIZED_ALU: if alu_type="AREA_OPTIMIZED" generate
59
 
60
      c_alu <= sum(31 downto 0) when alu_function=alu_add or alu_function=alu_subtract else (others => 'Z');
61
      c_alu <= ZERO(31 downto 1) & sum(32) when alu_function=alu_less_than or alu_function=alu_less_than_signed else (others => 'Z');
62
      c_alu <= a_in or  b_in    when alu_function=alu_or else (others => 'Z');
63
      c_alu <= a_in and b_in    when alu_function=alu_and else (others => 'Z');
64
      c_alu <= a_in xor b_in    when alu_function=alu_xor else (others => 'Z');
65
      c_alu <= a_in nor b_in    when alu_function=alu_nor else (others => 'Z');
66
      c_alu <= ZERO             when alu_function=alu_nothing else (others => 'Z');
67
 
68
   end generate;
69
 
70
   generic_adder: if adder_type = "GENERIC" generate
71 47 rhoads
      sum <= bv_adder(aa, bb, do_add);
72
   end generate; --generic_adder
73 112 rhoads
 
74 47 rhoads
   --For Altera
75 112 rhoads
   lpm_adder: if adder_type = "ALTERA" generate
76 47 rhoads
      lpm_add_sub_component : lpm_add_sub
77
      GENERIC MAP (
78
         lpm_width => 33,
79
         lpm_direction => "UNUSED",
80
         lpm_type => "LPM_ADD_SUB",
81
         lpm_hint => "ONE_INPUT_IS_CONSTANT=NO"
82
      )
83
      PORT MAP (
84
         dataa => aa,
85
         add_sub => do_add,
86
         datab => bb,
87
         result => sum
88
      );
89
   end generate; --lpm_adder
90
 
91 112 rhoads
   -- synopsys synthesis_on
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.