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 := "DEFAULT";
|
generic(alu_type : string := "DEFAULT");
|
alu_type : string := "DEFAULT");
|
|
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
|
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;
|
signal sum : std_logic_vector(32 downto 0);
|
|
signal less_than : std_logic;
|
begin
|
begin
|
|
|
do_add <= '1' when alu_function = ALU_ADD else '0';
|
do_add <= '1' when alu_function = ALU_ADD else '0';
|
sign_ext <= '0' when alu_function = ALU_LESS_THAN else '1';
|
sum <= bv_adder(a_in, b_in, do_add);
|
aa <= (a_in(31) and sign_ext) & a_in;
|
less_than <= sum(32) when a_in(31) = b_in(31) or alu_function = ALU_LESS_THAN
|
bb <= (b_in(31) and sign_ext) & b_in;
|
else a_in(31);
|
|
|
-- synthesis translate_off
|
|
GENERIC_ALU: if alu_type = "DEFAULT" generate
|
GENERIC_ALU: if alu_type = "DEFAULT" generate
|
-- synthesis translate_on
|
c_alu <= sum(31 downto 0) when alu_function=ALU_ADD or
|
|
alu_function=ALU_SUBTRACT else
|
c_alu <= sum(31 downto 0) when alu_function=ALU_ADD or alu_function=ALU_SUBTRACT else
|
ZERO(31 downto 1) & less_than when alu_function=ALU_LESS_THAN or
|
ZERO(31 downto 1) & sum(32) when alu_function=ALU_LESS_THAN or alu_function=ALU_LESS_THAN_SIGNED else
|
alu_function=ALU_LESS_THAN_SIGNED else
|
a_in or b_in when alu_function=ALU_OR else
|
a_in or b_in when alu_function=ALU_OR else
|
a_in and b_in when alu_function=ALU_AND else
|
a_in and b_in when alu_function=ALU_AND else
|
a_in xor b_in when alu_function=ALU_XOR else
|
a_in xor b_in when alu_function=ALU_XOR else
|
a_in nor b_in when alu_function=ALU_NOR else
|
a_in nor b_in when alu_function=ALU_NOR else
|
ZERO;
|
ZERO;
|
|
|
-- synthesis translate_off
|
|
end generate;
|
end generate;
|
-- synthesis translate_on
|
|
|
|
-- synopsys synthesis_off
|
|
|
|
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');
|
AREA_OPTIMIZED_ALU: if alu_type/="DEFAULT" generate
|
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 <= sum(31 downto 0) when alu_function=ALU_ADD or
|
|
alu_function=ALU_SUBTRACT else (others => 'Z');
|
|
c_alu <= ZERO(31 downto 1) & less_than 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 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 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 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 <= a_in nor b_in when alu_function=ALU_NOR else (others => 'Z');
|
c_alu <= ZERO when alu_function=ALU_NOTHING else (others => 'Z');
|
c_alu <= ZERO when alu_function=ALU_NOTHING else (others => 'Z');
|
|
|
end generate;
|
end generate;
|
|
|
generic_adder: if adder_type = "DEFAULT" generate
|
|
sum <= bv_adder(aa, bb, do_add);
|
|
end generate; --generic_adder
|
|
|
|
--For Altera
|
|
lpm_adder: if adder_type = "ALTERA" generate
|
|
lpm_add_sub_component : lpm_add_sub
|
|
GENERIC MAP (
|
|
lpm_width => 33,
|
|
lpm_direction => "UNUSED",
|
|
lpm_type => "LPM_ADD_SUB",
|
|
lpm_hint => "ONE_INPUT_IS_CONSTANT=NO"
|
|
)
|
|
PORT MAP (
|
|
dataa => aa,
|
|
add_sub => do_add,
|
|
datab => bb,
|
|
result => sum
|
|
);
|
|
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
|