📄 fixed_synth.vhdl
字号:
-- Synthesis test for the fixed point math package-- This test is designed to be synthesizable and exercise much of the package.-- Created for vhdl-200x by David Bishop (dbishop@vhdl.org)-- ---------------------------------------------------------------------- modification history : Last Modified $Date: 2006-06-08 10:49:35-04 $-- Version $Id: fixed_synth.vhdl,v 1.1 2006-06-08 10:49:35-04 l435385 Exp $-- --------------------------------------------------------------------library ieee, ieee_proposed;use ieee.std_logic_1164.all;use ieee.numeric_std.all;use ieee_proposed.math_utility_pkg.all;use ieee_proposed.fixed_pkg.all;entity fixed_synth is port ( in1, in2 : in STD_LOGIC_VECTOR (15 downto 0); -- inputs out1 : out STD_LOGIC_VECTOR (15 downto 0); -- output cmd : in STD_LOGIC_VECTOR (3 downto 0); clk, rst_n : in STD_ULOGIC); -- clk and resetend entity fixed_synth;architecture rtl of fixed_synth is subtype sfixed7 is sfixed (3 downto -3); -- 7 bit subtype sfixed16 is sfixed (7 downto -8); -- 16 bit type cmd_type is array (1 to 15) of STD_ULOGIC_VECTOR (cmd'range); -- cmd signal cmdarray : cmd_type; -- command pipeline type cry_type is array (0 to 4) of sfixed16; -- arrays signal outarray0, outarray1, outarray2, outarray3, outarray4, outarray5, outarray6, outarray7, outarray8, outarray9, outarray10, outarray11, outarray12, outarray13, outarray14, outarray15 : sfixed16; signal in1reg3, in2reg3 : sfixed16; -- register stagesbegin -- architecture rtl -- purpose: "0000" test the "+" operator cmd0reg : process (clk, rst_n) is variable in1pin2 : sfixed (SFixed_high(7, -8, '+', 7, -8) downto SFixed_low(7, -8, '+', 7, -8)); variable outarray : cry_type; -- array for output variable in1array, in2array : cry_type; -- array for input begin -- process cmd0reg if rst_n = '0' then -- asynchronous reset (active low) outarray0 <= (others => '0'); jrloop : for j in 0 to 4 loop outarray (j) := (others => '0'); in1array (j) := (others => '0'); in2array (j) := (others => '0'); end loop jrloop; elsif rising_edge(clk) then -- rising clock edge outarray0 <= outarray(4); jcloop : for j in 4 downto 1 loop outarray (j) := outarray(j-1); end loop jcloop; j1loop : for j in 3 downto 1 loop in1array (j) := in1array(j-1); end loop j1loop; j2loop : for j in 3 downto 1 loop in2array (j) := in2array(j-1); end loop j2loop; in1array(0) := in1reg3; in2array(0) := in2reg3; in1pin2 := in1array(3) + in2array(3); outarray(0) := resize (in1pin2, outarray(0)); end if; end process cmd0reg; -- purpose: "0001" test the "-" operator cmd1reg : process (clk, rst_n) is variable outarray : cry_type; -- array for output variable in1array, in2array : cry_type; -- array for input variable in1min2 : sfixed (SFixed_high(in1array(0), '-', in2array(0)) downto SFixed_low(in1array(0), '-', in2array(0)));-- variable in1min2 : sfixed (SFixed_high(7, -8, '-', 7, -8) downto-- SFixed_low(7, -8, '-', 7, -8)); begin -- process cmd0reg if rst_n = '0' then -- asynchronous reset (active low) outarray1 <= (others => '0'); jrloop : for j in 0 to 4 loop outarray (j) := (others => '0'); in1array (j) := (others => '0'); in2array (j) := (others => '0'); end loop jrloop; elsif rising_edge(clk) then -- rising clock edge outarray1 <= outarray(4); jcloop : for j in 4 downto 1 loop outarray (j) := outarray(j-1); end loop jcloop; j1loop : for j in 3 downto 1 loop in1array (j) := in1array(j-1); end loop j1loop; j2loop : for j in 3 downto 1 loop in2array (j) := in2array(j-1); end loop j2loop; in1array(0) := in1reg3; in2array(0) := in2reg3; in1min2 := in1array(3) - in2array(3); outarray(0) := resize (in1min2, outarray(0)); end if; end process cmd1reg; -- purpose: "0010" test the "*" operator cmd2reg : process (clk, rst_n) is-- variable in1min2 : sfixed (SFixed_high(in1reg3, '*', in2reg3) downto-- SFixed_low(in1reg3, '*', in2reg3)); variable in1min2 : sfixed (SFixed_high(7, -8, '*', 7, -8) downto SFixed_low(7, -8, '*', 7, -8)); variable outarray : cry_type; -- array for output variable in1array, in2array : cry_type; -- array for input begin -- process cmd0reg if rst_n = '0' then -- asynchronous reset (active low) outarray2 <= (others => '0'); jrloop : for j in 0 to 4 loop outarray (j) := (others => '0'); in1array (j) := (others => '0'); in2array (j) := (others => '0'); end loop jrloop; elsif rising_edge(clk) then -- rising clock edge outarray2 <= outarray(4); jcloop : for j in 4 downto 1 loop outarray (j) := outarray(j-1); end loop jcloop; j1loop : for j in 3 downto 1 loop in1array (j) := in1array(j-1); end loop j1loop; j2loop : for j in 3 downto 1 loop in2array (j) := in2array(j-1); end loop j2loop; in1array(0) := in1reg3; in2array(0) := in2reg3; in1min2 := in1array(3) * in2array(3); outarray(0) := resize (in1min2, outarray(0)); end if; end process cmd2reg; -- purpose: "0011" test the "/" operator cmd3reg : process (clk, rst_n) is variable in1min2 : sfixed (SFixed_high(in1reg3'high, in1reg3'low, '/', in2reg3'high, in2reg3'low) downto SFixed_low(in1reg3'high, in1reg3'low, '/', in2reg3'high, in2reg3'low)); variable outarray : cry_type; -- array for output variable in1array, in2array : cry_type; -- array for input begin -- process cmd3reg if rst_n = '0' then -- asynchronous reset (active low) outarray3 <= (others => '0'); jrloop : for j in 0 to 4 loop outarray (j) := (others => '0'); in1array (j) := (others => '0'); in2array (j) := to_sfixed(1, in2array(0)); end loop jrloop; elsif rising_edge(clk) then -- rising clock edge outarray3 <= outarray(4); jcloop : for j in 4 downto 1 loop outarray (j) := outarray(j-1); end loop jcloop; j1loop : for j in 3 downto 1 loop in1array (j) := in1array(j-1); end loop j1loop; j2loop : for j in 3 downto 1 loop in2array (j) := in2array(j-1); end loop j2loop; in1array(0) := in1reg3; if (in2reg3 = 0) then in2array(0) := to_sfixed(1, in2array(0)); else in2array(0) := in2reg3; end if; in1min2 := in1array(3) / in2array(3); outarray(0) := resize (in1min2, outarray(0)); end if; end process cmd3reg; -- purpose: "0100" test the "+" operator cmd4reg : process (clk, rst_n) is variable in1pin2 : ufixed (uFixed_high(7, -8, '+', 7, -8) downto uFixed_low(7, -8, '+', 7, -8)); variable outarray : cry_type; -- array for output variable in1array, in2array : cry_type; -- array for input begin -- process cmd0reg if rst_n = '0' then -- asynchronous reset (active low) outarray4 <= (others => '0'); jrloop : for j in 0 to 4 loop outarray (j) := (others => '0'); in1array (j) := (others => '0'); in2array (j) := (others => '0'); end loop jrloop; elsif rising_edge(clk) then -- rising clock edge outarray4 <= outarray(4); jcloop : for j in 4 downto 1 loop outarray (j) := outarray(j-1); end loop jcloop; j1loop : for j in 3 downto 1 loop in1array (j) := in1array(j-1); end loop j1loop; j2loop : for j in 3 downto 1 loop in2array (j) := in2array(j-1); end loop j2loop; in1array(0) := in1reg3; in2array(0) := in2reg3; in1pin2 := ufixed(in1array(3)) + ufixed(in2array(3)); outarray(0) := sfixed (resize (in1pin2, outarray4'high, outarray4'low)); end if; end process cmd4reg; -- purpose: "0101" test the "-" operator cmd5reg : process (clk, rst_n) is variable in1min2 : ufixed (uFixed_high(7, -8, '-', 7, -8) downto uFixed_low(7, -8, '-', 7, -8)); variable outarray : cry_type; -- array for output variable in1array, in2array : cry_type; -- array for input begin -- process cmd0reg if rst_n = '0' then -- asynchronous reset (active low) outarray5 <= (others => '0'); jrloop : for j in 0 to 4 loop outarray (j) := (others => '0'); in1array (j) := (others => '0'); in2array (j) := (others => '0'); end loop jrloop; elsif rising_edge(clk) then -- rising clock edge outarray5 <= outarray(4); jcloop : for j in 4 downto 1 loop outarray (j) := outarray(j-1); end loop jcloop; j1loop : for j in 3 downto 1 loop in1array (j) := in1array(j-1); end loop j1loop; j2loop : for j in 3 downto 1 loop in2array (j) := in2array(j-1); end loop j2loop; in1array(0) := in1reg3; in2array(0) := in2reg3; in1min2 := ufixed(in1array(3)) - ufixed(in2array(3)); outarray(0) := sfixed(resize (in1min2, outarray5'high, outarray5'low)); end if; end process cmd5reg; -- purpose: "0110" test the "*" operator cmd6reg : process (clk, rst_n) is variable in1min2 : ufixed (uFixed_high(7, -8, '*', 7, -8) downto uFixed_low(7, -8, '*', 7, -8)); variable outarray : cry_type; -- array for output variable in1array, in2array : cry_type; -- array for input begin -- process cmd0reg if rst_n = '0' then -- asynchronous reset (active low) outarray6 <= (others => '0'); jrloop : for j in 0 to 4 loop outarray (j) := (others => '0'); in1array (j) := (others => '0'); in2array (j) := (others => '0'); end loop jrloop; elsif rising_edge(clk) then -- rising clock edge outarray6 <= outarray(4); jcloop : for j in 4 downto 1 loop outarray (j) := outarray(j-1); end loop jcloop; j1loop : for j in 3 downto 1 loop in1array (j) := in1array(j-1); end loop j1loop; j2loop : for j in 3 downto 1 loop in2array (j) := in2array(j-1); end loop j2loop; in1array(0) := in1reg3; in2array(0) := in2reg3; in1min2 := ufixed(in1array(3)) * ufixed(in2array(3)); outarray(0) := sfixed(resize (in1min2, outarray6'high, outarray6'low)); end if; end process cmd6reg; -- purpose: "0111" test the "/" operator cmd7reg : process (clk, rst_n) is variable in1min2 : ufixed (uFixed_high(7, -8, '/', 7, -8) downto uFixed_low(7, -8, '/', 7, -8)); variable outarray : cry_type; -- array for output variable in1array, in2array : cry_type; -- array for input begin -- process cmd0reg if rst_n = '0' then -- asynchronous reset (active low) outarray7 <= (others => '0'); jrloop : for j in 0 to 4 loop outarray (j) := (others => '0'); in1array (j) := (others => '0'); in2array (j) := sfixed(to_ufixed(1, in2reg3'high, in2reg3'low)); end loop jrloop; elsif rising_edge(clk) then -- rising clock edge outarray7 <= outarray(4); jcloop : for j in 4 downto 1 loop outarray (j) := outarray(j-1); end loop jcloop; j1loop : for j in 3 downto 1 loop in1array (j) := in1array(j-1); end loop j1loop; j2loop : for j in 3 downto 1 loop in2array (j) := in2array(j-1); end loop j2loop; in1array(0) := in1reg3; if (in2reg3 = 0) then in2array(0) := sfixed(to_ufixed(1, in2reg3'high, in2reg3'low)); else in2array(0) := in2reg3; end if; in1min2 := ufixed(in1array(3)) / ufixed(in2array(3)); outarray(0) := sfixed(resize (in1min2, outarray7'high, outarray7'low)); end if; end process cmd7reg; -- purpose: "1000" test the resize test cmd8reg : process (clk, rst_n) is variable tmpfp71, tmpfp72 : sfixed7; -- 8 bit fp number variable outarray : cry_type; -- array for output variable in1array, in2array : cry_type; -- array for input begin -- process cmd0reg if rst_n = '0' then -- asynchronous reset (active low) outarray8 <= (others => '0'); jrloop : for j in 0 to 4 loop outarray (j) := (others => '0'); in1array (j) := (others => '0'); in2array (j) := (others => '0'); end loop jrloop; elsif rising_edge(clk) then -- rising clock edge outarray8 <= outarray(4); jcloop : for j in 4 downto 1 loop outarray (j) := outarray(j-1); end loop jcloop; j1loop : for j in 3 downto 1 loop in1array (j) := in1array(j-1); end loop j1loop; j2loop : for j in 3 downto 1 loop in2array (j) := in2array(j-1); end loop j2loop; in1array(0) := in1reg3; in2array(0) := in2reg3; -- Resize test Convert inputs into two 8 bit numbers tmpfp71 := resize (in1array(3), tmpfp71'high, tmpfp71'low, fixed_wrap, fixed_truncate); tmpfp72 := resize (in2array(3), tmpfp72'high, tmpfp72'low, fixed_saturate, fixed_round); outarray(0) := (others => '0'); fx1 : for i in tmpfp71'range loop outarray(0)(i+4) := tmpfp71(i); end loop fx1; fx2 : for i in tmpfp72'range loop outarray(0)(i-4) := tmpfp72(i); end loop fx2; end if; end process cmd8reg; -- purpose: "1001" test the to_signed/unsigned test cmd9reg : process (clk, rst_n) is variable tmp : STD_LOGIC_VECTOR (1 downto 0); -- temp variable tmpsig : SIGNED (7 downto 0); -- signed number variable tmpuns : UNSIGNED (15 downto 0); -- unsigned number variable tmpint : INTEGER; variable outarray : cry_type; -- array for output variable in1array, in2array : cry_type; -- array for input begin -- process cmd0reg if rst_n = '0' then -- asynchronous reset (active low) outarray9 <= (others => '0'); jrloop : for j in 0 to 4 loop outarray (j) := (others => '0'); in1array (j) := (others => '0'); in2array (j) := (others => '0'); end loop jrloop; elsif rising_edge(clk) then -- rising clock edge outarray9 <= outarray(4); jcloop : for j in 4 downto 1 loop outarray (j) := outarray(j-1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -