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

Subversion Repositories mlite

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

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 131 rhoads
   generic(adder_type : string := "DEFAULT";
18
           alu_type   : string := "DEFAULT");
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 47 rhoads
   signal aa, bb, sum : std_logic_vector(32 downto 0);
27
   signal do_add      : std_logic;
28 112 rhoads
   signal sign_ext    : std_logic;
29 2 rhoads
begin
30
 
31 128 rhoads
   do_add <= '1' when alu_function = ALU_ADD else '0';
32
   sign_ext <= '0' when alu_function = ALU_LESS_THAN else '1';
33 47 rhoads
   aa <= (a_in(31) and sign_ext) & a_in;
34
   bb <= (b_in(31) and sign_ext) & b_in;
35
 
36 112 rhoads
   -- synthesis translate_off
37 131 rhoads
   GENERIC_ALU: if alu_type = "DEFAULT" generate
38 112 rhoads
   -- synthesis translate_on
39 2 rhoads
 
40 128 rhoads
      c_alu <= sum(31 downto 0) when alu_function=ALU_ADD or alu_function=ALU_SUBTRACT else
41
               ZERO(31 downto 1) & sum(32) when alu_function=ALU_LESS_THAN or alu_function=ALU_LESS_THAN_SIGNED else
42
               a_in or  b_in    when alu_function=ALU_OR else
43
               a_in and b_in    when alu_function=ALU_AND else
44
               a_in xor b_in    when alu_function=ALU_XOR else
45
               a_in nor b_in    when alu_function=ALU_NOR else
46 112 rhoads
               ZERO;
47 2 rhoads
 
48 112 rhoads
   -- synthesis translate_off
49
   end generate;
50
   -- synthesis translate_on
51 47 rhoads
 
52 112 rhoads
   -- synopsys synthesis_off
53
 
54
   AREA_OPTIMIZED_ALU: if alu_type="AREA_OPTIMIZED" generate
55
 
56 128 rhoads
      c_alu <= sum(31 downto 0) when alu_function=ALU_ADD or alu_function=ALU_SUBTRACT else (others => 'Z');
57
      c_alu <= ZERO(31 downto 1) & sum(32) when alu_function=ALU_LESS_THAN or alu_function=ALU_LESS_THAN_SIGNED else (others => 'Z');
58
      c_alu <= a_in or  b_in    when alu_function=ALU_OR else (others => 'Z');
59
      c_alu <= a_in and b_in    when alu_function=ALU_AND else (others => 'Z');
60
      c_alu <= a_in xor b_in    when alu_function=ALU_XOR else (others => 'Z');
61
      c_alu <= a_in nor b_in    when alu_function=ALU_NOR else (others => 'Z');
62
      c_alu <= ZERO             when alu_function=ALU_NOTHING else (others => 'Z');
63 112 rhoads
 
64
   end generate;
65
 
66 131 rhoads
   generic_adder: if adder_type = "DEFAULT" generate
67 47 rhoads
      sum <= bv_adder(aa, bb, do_add);
68
   end generate; --generic_adder
69 112 rhoads
 
70 47 rhoads
   --For Altera
71 112 rhoads
   lpm_adder: if adder_type = "ALTERA" generate
72 47 rhoads
      lpm_add_sub_component : lpm_add_sub
73
      GENERIC MAP (
74
         lpm_width => 33,
75
         lpm_direction => "UNUSED",
76
         lpm_type => "LPM_ADD_SUB",
77
         lpm_hint => "ONE_INPUT_IS_CONSTANT=NO"
78
      )
79
      PORT MAP (
80
         dataa => aa,
81
         add_sub => do_add,
82
         datab => bb,
83
         result => sum
84
      );
85
   end generate; --lpm_adder
86
 
87 112 rhoads
   -- synopsys synthesis_on
88
 
89 2 rhoads
end; --architecture logic
90
 

powered by: WebSVN 2.1.0

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