📄 220model.vhd
字号:
i_dataa <= (dataa(lpm_width) & dataa);
i_datab <= (datab(lpm_width) & datab);
-- PROCESS DECLARATION
-- basic error checking for invalid parameters
MSG: process
begin
if (lpm_width <= 0) then
ASSERT FALSE
REPORT "Value of lpm_width parameter must be greater than 0!"
SEVERITY ERROR;
end if;
if (lpm_pipeline < 0) then
ASSERT FALSE
REPORT "Value of lpm_pipeline parameter must be greater than or equal to 0!"
SEVERITY ERROR;
end if;
wait;
end process MSG;
process(aclr, clock, i_dataa, i_datab, cin, add_sub)
variable resulttmp : T_RESULTTMP := (OTHERS => (OTHERS => '0'));
variable couttmp : std_logic_vector(0 to lpm_pipeline) := (OTHERS => '0');
variable overflowtmp : std_logic_vector(0 to lpm_pipeline) := (OTHERS => '0');
variable i_cin : std_logic;
begin
if (lpm_pipeline >= 0) then
if ((lpm_direction = "ADD") or
((lpm_direction = "UNUSED") and (add_sub = '1'))) then
if (cin = 'Z') then
i_cin := '0';
else
i_cin := cin;
end if;
-- Perform as adder
resulttmp(lpm_pipeline) := i_dataa + i_datab + i_cin;
couttmp(lpm_pipeline) := resulttmp(lpm_pipeline)(lpm_width) xor
dataa(lpm_width) xor
datab(lpm_width);
if ((dataa(lpm_width) = '0') and (datab(lpm_width) = '0') and
(resulttmp(lpm_pipeline)(lpm_width-1) = '1')) or
((dataa(lpm_width) = '1') and (datab(lpm_width) = '1') and
(resulttmp(lpm_pipeline)(lpm_width-1) = '0')) then
overflowtmp(lpm_pipeline) := '1';
else
overflowtmp(lpm_pipeline) := '0';
end if;
elsif ((lpm_direction = "SUB") or
((lpm_direction = "UNUSED") and (add_sub = '0'))) then
if (cin = 'Z') then
i_cin := '1';
else
i_cin := cin;
end if;
-- Perform as subtrator
resulttmp(lpm_pipeline) := i_dataa - i_datab + i_cin - 1;
couttmp(lpm_pipeline) := (not resulttmp(lpm_pipeline)(lpm_width)) xor
dataa(lpm_width) xor
datab(lpm_width);
if ((dataa(lpm_width) = '0') and (datab(lpm_width) = '1') and
(resulttmp(lpm_pipeline)(lpm_width-1) = '1')) or
((dataa(lpm_width) = '1') and (datab(lpm_width) = '0') and
(resulttmp(lpm_pipeline)(lpm_width-1) = '0')) then
overflowtmp(lpm_pipeline) := '1';
else
overflowtmp(lpm_pipeline) := '0';
end if;
elsif (lpm_direction /= "UNUSED") then
ASSERT FALSE
REPORT "Illegal lpm_direction property value for LPM_ADD_SUB!"
SEVERITY ERROR;
end if;
if (lpm_pipeline > 0) then -- Pipeline the result
if (aclr = '1') then
overflowtmp := (OTHERS => '0');
couttmp := (OTHERS => '0');
for i in 0 to lpm_pipeline loop
resulttmp(i) := (OTHERS => '0');
end loop;
elsif (clock'event and (clock = '1') and (clken = '1')) then
overflowtmp(0 to lpm_pipeline - 1) := overflowtmp(1 to lpm_pipeline);
couttmp(0 to lpm_pipeline - 1) := couttmp(1 to lpm_pipeline);
resulttmp(0 to lpm_pipeline - 1) := resulttmp(1 to lpm_pipeline);
end if;
end if;
-- send the pipeline result to output ports
cout <= couttmp(0);
overflow <= overflowtmp(0);
result <= resulttmp(0)(lpm_width-1 downto 0);
end if;
end process;
end LPM_SYN;
-- END OF ARCHITECTURE
---START_ENTITY_HEADER---------------------------------------------------------
--
-- Entity Name : lpm_add_sub_unsigned
--
-- Description : This entity is instiatiated by lpm_add_sub megafunction to perform
-- adder/subtrator function for unsigned number.
--
-- Limitation : n/a
--
-- Results Expected: If performs as adder, the result will be dataa[]+datab[]+cin.
-- If performs as subtractor, the result will be dataa[]-datab[]+cin-1.
-- Also returns carry out bit and overflow status bit.
--
---END_ENTITY_HEADER-----------------------------------------------------------
-- LIBRARY USED----------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
use work.LPM_COMPONENTS.all;
-- ENTITY DECLARATION
entity LPM_ADD_SUB_UNSIGNED is
generic (
lpm_width : natural; -- MUST be greater than 0
lpm_direction : string := "UNUSED";
lpm_pipeline : natural := 0;
lpm_type : string := "LPM_ADD_SUB";
lpm_hint : string := "UNUSED"
);
port (
dataa : in std_logic_vector(lpm_width-1 downto 0);
datab : in std_logic_vector(lpm_width-1 downto 0);
cin : in std_logic := 'Z';
add_sub : in std_logic := '1';
clock : in std_logic := '0';
aclr : in std_logic := '0';
clken : in std_logic := '1';
result : out std_logic_vector(lpm_width-1 downto 0);
cout : out std_logic;
overflow : out std_logic
);
end LPM_ADD_SUB_UNSIGNED;
-- END OF ENTITY
-- BEGINNING OF ARCHITECTURE
architecture LPM_SYN of LPM_ADD_SUB_UNSIGNED is
-- SIGNAL DECLARATION
signal i_dataa, i_datab : std_logic_vector(lpm_width downto 0);
-- TYPE DECLARATION
type T_RESULTTMP IS ARRAY (0 to lpm_pipeline) of std_logic_vector(lpm_width downto 0);
begin
i_dataa <= ('0' & dataa);
i_datab <= ('0' & datab);
-- PROCESS DECLARATION
-- basic error checking for invalid parameters
MSG: process
begin
if (lpm_width <= 0) then
ASSERT FALSE
REPORT "Value of lpm_width parameter must be greater than 0!"
SEVERITY ERROR;
end if;
if (lpm_pipeline < 0) then
ASSERT FALSE
REPORT "Value of lpm_pipeline parameter must be greater than or equal to 0!"
SEVERITY ERROR;
end if;
wait;
end process MSG;
process(aclr, clock, i_dataa, i_datab, cin, add_sub)
variable resulttmp : T_RESULTTMP := (OTHERS => (OTHERS => '0'));
variable couttmp : std_logic_vector(0 to lpm_pipeline) := (OTHERS => '0');
variable overflowtmp : std_logic_vector(0 to lpm_pipeline) := (OTHERS => '0');
variable i_cin : std_logic;
begin
if (lpm_pipeline >= 0) then
if ((lpm_direction = "ADD") or
((lpm_direction = "UNUSED") and (add_sub = '1'))) then
if (cin = 'Z') then
i_cin := '0';
else
i_cin := cin;
end if;
-- Perform as adder
resulttmp(lpm_pipeline) := i_dataa + i_datab + i_cin;
couttmp(lpm_pipeline) := resulttmp(lpm_pipeline)(lpm_width);
elsif ((lpm_direction = "SUB") or
((lpm_direction = "UNUSED") and (add_sub = '0'))) then
if (cin = 'Z') then
i_cin := '1';
else
i_cin := cin;
end if;
-- Perform as subtractor
resulttmp(lpm_pipeline) := i_dataa - i_datab + i_cin - 1;
couttmp(lpm_pipeline) := not resulttmp(lpm_pipeline)(lpm_width);
elsif (lpm_direction /= "UNUSED") then
ASSERT FALSE
REPORT "Illegal lpm_direction property value for LPM_ADD_SUB!"
SEVERITY ERROR;
end if;
overflowtmp(lpm_pipeline) := resulttmp(lpm_pipeline)(lpm_width);
if (lpm_pipeline > 0) then -- Pipeline the result
if (aclr = '1') then
overflowtmp := (OTHERS => '0');
couttmp := (OTHERS => '0');
for i in 0 to lpm_pipeline loop
resulttmp(i) := (OTHERS => '0');
end loop;
elsif (clock'event and (clock = '1') and (clken = '1')) then
overflowtmp(0 to lpm_pipeline - 1) := overflowtmp(1 to lpm_pipeline);
couttmp(0 to lpm_pipeline - 1) := couttmp(1 to lpm_pipeline);
resulttmp(0 to lpm_pipeline - 1) := resulttmp(1 to lpm_pipeline);
end if;
end if;
-- Send the pipelined result to output ports
cout <= couttmp(0);
overflow <= overflowtmp(0);
result <= resulttmp(0)(lpm_width-1 downto 0);
end if;
end process;
end LPM_SYN;
-- END OF ARCHITECTURE
---START_ENTITY_HEADER---------------------------------------------------------
--
-- Entity Name : lpm_add_sub
--
-- Description : Parameterized adder/subtractor megafunction.
--
-- Limitation : n/a
--
-- Results Expected: If performs as adder, the result will be dataa[]+datab[]+cin.
-- If performs as subtractor, the result will be dataa[]-datab[]+cin-1.
-- Also returns carry out bit and overflow status bit.
--
---END_ENTITY_HEADER-----------------------------------------------------------
-- LIBRARY USED----------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
use work.LPM_COMPONENTS.all;
-- ENTITY DECLARATION
entity LPM_ADD_SUB is
generic (
lpm_width : natural; -- MUST be greater than 0
lpm_representation : string := "SIGNED";
lpm_direction : string := "UNUSED";
lpm_pipeline : natural := 0;
lpm_type : string := "LPM_ADD_SUB";
lpm_hint : string := "UNUSED"
);
port (
dataa : in std_logic_vector(lpm_width-1 downto 0);
datab : in std_logic_vector(lpm_width-1 downto 0);
cin : in std_logic := 'Z';
add_sub : in std_logic := '1';
clock : in std_logic := '0';
aclr : in std_logic := '0';
clken : in std_logic := '1';
result : out std_logic_vector(lpm_width-1 downto 0);
cout : out std_logic;
overflow : out std_logic
);
end LPM_ADD_SUB;
-- END OF ENTITY
-- BEGINNING OF ARCHITECTURE
architecture LPM_SYN of LPM_ADD_SUB is
-- COMPONENT DECLARATION
component LPM_ADD_SUB_SIGNED
generic (
lpm_width : natural; -- MUST be greater than 0
lpm_direction : string := "UNUSED";
lpm_pipeline : natural := 0;
lpm_type : string := "LPM_ADD_SUB";
lpm_hint : string := "UNUSED"
);
port (
dataa : in std_logic_vector(lpm_width downto 1);
datab : in std_logic_vector(lpm_width downto 1);
cin : in std_logic := 'Z';
add_sub : in std_logic := '1';
clock : in std_logic := '0';
aclr : in std_logic := '0';
clken : in std_logic := '1';
result : out std_logic_vector(lpm_width-1 downto 0);
cout : out std_logic;
overflow : out std_logic
);
end component;
component LPM_ADD_SUB_UNSIGNED
generic (
lpm_width : natural; -- MUST be greater than 0
lpm_direction : string := "UNUSED";
lpm_pipeline : natural := 0;
lpm_type : string := "LPM_ADD_SUB";
lpm_hint : string := "UNUSED"
);
port (
dataa : in std_logic_vector(lpm_width-1 downto 0);
datab : in std_logic_vector(lpm_width-1 downto 0);
cin : in std_logic := 'Z';
add_sub : in std_logic := '1';
clock : in std_logic := '0';
aclr : in std_logic := '0';
clken : in std_logic := '1';
result : out std_logic_vector(lpm_width-1 downto 0);
cout : out std_logic;
overflow : out std_logic
);
end component;
begin
-- PROCESS DECLARATION
-- basic error checking for invalid parameters
MSG: process
begin
if ((lpm_representation /= "SIGNED") and
(lpm_representation /= "UNSIGNED")) then
ASSERT FALSE
REPORT "Value of lpm_representation parameter must be SIGNED or UNSIGNED!"
SEVERITY ERROR;
end if;
wait;
end process MSG;
L1: if (lpm_representation = "UNSIGNED") generate
U: LPM_ADD_SUB_UNSIGNED
generic map (
lpm_width => lpm_width,
lpm_direction => lpm_direction,
lpm_pipeline => lpm_pipeline,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -