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

Subversion Repositories mlite

[/] [mlite/] [trunk/] [vhdl/] [alu.vhd] - Diff between revs 81 and 112

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 81 Rev 112
Line 12... Line 12...
library ieee;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_1164.all;
use work.mlite_pack.all;
use work.mlite_pack.all;
 
 
entity alu is
entity alu is
   generic(adder_type : string := "GENERIC");
   generic(adder_type : string := "GENERIC";
 
           alu_type   : string := "GENERIC");
   port(a_in         : in  std_logic_vector(31 downto 0);
   port(a_in         : in  std_logic_vector(31 downto 0);
        b_in         : in  std_logic_vector(31 downto 0);
        b_in         : in  std_logic_vector(31 downto 0);
        alu_function : in  alu_function_type;
        alu_function : in  alu_function_type;
        c_alu        : out std_logic_vector(31 downto 0));
        c_alu        : out std_logic_vector(31 downto 0));
end; --alu
end; --alu
 
 
architecture logic of alu is
architecture logic of alu is
--   type alu_function_type is (alu_nothing, alu_add, alu_subtract, 
--   type alu_function_type is (alu_nothing, alu_add, alu_subtract, 
--      alu_less_than, alu_less_than_signed, 
--      alu_less_than, alu_less_than_signed, 
--      alu_or, alu_and, alu_xor, alu_nor);
--      alu_or, alu_and, alu_xor, alu_nor);
 
 
   signal aa, bb, sum : std_logic_vector(32 downto 0);
   signal aa, bb, sum : std_logic_vector(32 downto 0);
   signal do_add      : std_logic;
   signal do_add      : std_logic;
 
   signal sign_ext    : std_logic;
begin
begin
 
 
alu_proc: process(a_in, b_in, alu_function, sum)
   do_add <= '1' when alu_function = alu_add else '0';
   variable sign_ext  : std_logic;
   sign_ext <= '0' when alu_function = alu_less_than else '1';
begin
 
   if alu_function = alu_add then
 
      do_add <= '1';
 
   else
 
      do_add <= '0';
 
   end if;
 
   if alu_function = alu_less_than then
 
      sign_ext := '0';
 
   else
 
      sign_ext := '1';
 
   end if;
 
   aa <= (a_in(31) and sign_ext) & a_in;
   aa <= (a_in(31) and sign_ext) & a_in;
   bb <= (b_in(31) and sign_ext) & b_in;
   bb <= (b_in(31) and sign_ext) & b_in;
 
 
   case alu_function is
   -- synthesis translate_off
   when alu_add | alu_subtract => --c=a+b
   GENERIC_ALU: if alu_type="GENERIC" generate
      c_alu <= sum(31 downto 0);
   -- synthesis translate_on
   when alu_less_than =>          --c=a<b
 
      c_alu <= ZERO(31 downto 1) & sum(32);
      c_alu <= sum(31 downto 0) when alu_function=alu_add or alu_function=alu_subtract else
   when alu_less_than_signed =>   --c=a<b;
               ZERO(31 downto 1) & sum(32) when alu_function=alu_less_than or alu_function=alu_less_than_signed else
      c_alu <= ZERO(31 downto 1) & sum(32);
               a_in or  b_in    when alu_function=alu_or else
   when alu_or =>                 --c=a|b
               a_in and b_in    when alu_function=alu_and else
      c_alu <= a_in or b_in;
               a_in xor b_in    when alu_function=alu_xor else
   when alu_and =>                --c=a&b
               a_in nor b_in    when alu_function=alu_nor else
      c_alu <= a_in and b_in;
               ZERO;
   when alu_xor =>                --c=a^b
 
      c_alu <= a_in xor b_in;
   -- synthesis translate_off
   when alu_nor =>                --c=~(a|b)
   end generate;
      c_alu <= a_in nor b_in;
   -- synthesis translate_on
   when others =>                 --alu_function = alu_nothing
 
      c_alu <= ZERO;
   -- synopsys synthesis_off
   end case;
 
 
   AREA_OPTIMIZED_ALU: if alu_type="AREA_OPTIMIZED" generate
 
 
 
      c_alu <= sum(31 downto 0) when alu_function=alu_add or alu_function=alu_subtract else (others => 'Z');
 
      c_alu <= ZERO(31 downto 1) & sum(32) when alu_function=alu_less_than or alu_function=alu_less_than_signed else (others => 'Z');
 
      c_alu <= a_in or  b_in    when alu_function=alu_or else (others => 'Z');
 
      c_alu <= a_in and b_in    when alu_function=alu_and else (others => 'Z');
 
      c_alu <= a_in xor b_in    when alu_function=alu_xor else (others => 'Z');
 
      c_alu <= a_in nor b_in    when alu_function=alu_nor else (others => 'Z');
 
      c_alu <= ZERO             when alu_function=alu_nothing else (others => 'Z');
 
 
end process;
   end generate;
 
 
 
   generic_adder: if adder_type = "GENERIC" generate
   generic_adder:
 
   if adder_type /= "ALTERA" generate
 
      sum <= bv_adder(aa, bb, do_add);
      sum <= bv_adder(aa, bb, do_add);
   end generate; --generic_adder
   end generate; --generic_adder
 
 
   --For Altera
   --For Altera
   lpm_adder:
   lpm_adder: if adder_type = "ALTERA" generate
   if adder_type = "ALTERA" generate
 
      lpm_add_sub_component : lpm_add_sub
      lpm_add_sub_component : lpm_add_sub
      GENERIC MAP (
      GENERIC MAP (
         lpm_width => 33,
         lpm_width => 33,
         lpm_direction => "UNUSED",
         lpm_direction => "UNUSED",
         lpm_type => "LPM_ADD_SUB",
         lpm_type => "LPM_ADD_SUB",
Line 88... Line 86...
         datab => bb,
         datab => bb,
         result => sum
         result => sum
      );
      );
   end generate; --lpm_adder
   end generate; --lpm_adder
 
 
 
   -- synopsys synthesis_on
 
 
end; --architecture logic
end; --architecture logic
 
 
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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