📄 float_synth.vhdl
字号:
--------------------------------------------------------------------------------- Synthesis test for the floating 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:50:32-04 $-- Version $Id: float_synth.vhdl,v 1.1 2006-06-08 10:50:32-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;use ieee_proposed.float_pkg.all;use ieee.math_real.all;entity float_synth is port ( in1, in2 : in std_logic_vector (31 downto 0); -- inputs out1 : out std_logic_vector (31 downto 0); -- output cmd : in std_logic_vector (3 downto 0); clk, rst_n : in std_ulogic); -- clk and resetend entity float_synth;architecture rtl of float_synth is subtype fp16 is float (6 downto -9); -- 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 15) of float32; -- arrays signal outx : cry_type; signal in1reg3, in2reg3 : float32; -- register stages begin -- architecture rtl -- purpose: "0000" test the "+" operator cmd0reg: process (clk, rst_n) is variable outarray : cry_type; -- array for output begin -- process cmd0reg if rst_n = '0' then -- asynchronous reset (active low) outx(0) <= ( others => '0'); jrloop: for j in 0 to 7 loop outarray (j) := (others => '0'); end loop jrloop; elsif rising_edge(clk) then -- rising clock edge outx(0) <= outarray(7); jcloop: for j in 7 downto 1 loop outarray (j) := outarray(j-1); end loop jcloop; outarray(0) := in1reg3 + in2reg3; end if; end process cmd0reg; -- purpose: "0001" test the "-" operator cmd1reg: process (clk, rst_n) is variable outarray : cry_type; -- array for output begin -- process cmd1reg if rst_n = '0' then -- asynchronous reset (active low) outx(1) <= ( others => '0'); jrloop: for j in 0 to 7 loop outarray (j) := (others => '0'); end loop jrloop; elsif rising_edge(clk) then -- rising clock edge outx(1) <= outarray(7); jcloop: for j in 7 downto 1 loop outarray (j) := outarray(j-1); end loop jcloop; outarray(0) := in1reg3 - in2reg3; end if; end process cmd1reg; -- purpose: "0010" test the "*" operator cmd2reg: process (clk, rst_n) is variable outarray : cry_type; -- array for output begin -- process cmd2reg if rst_n = '0' then -- asynchronous reset (active low) outx(2) <= ( others => '0'); jrloop: for j in 0 to 7 loop outarray (j) := (others => '0'); end loop jrloop; elsif rising_edge(clk) then -- rising clock edge outx(2) <= outarray(7); jcloop: for j in 7 downto 1 loop outarray (j) := outarray(j-1); end loop jcloop; outarray(0) := in1reg3 * in2reg3; end if; end process cmd2reg; -- purpose: "0011" performs test the "/" operator cmd3reg: process (clk, rst_n) is variable outarray : cry_type; -- array for output begin -- process cmd1reg if rst_n = '0' then -- asynchronous reset (active low) outx(3) <= ( others => '0'); jrloop: for j in 0 to 7 loop outarray (j) := (others => '0'); end loop jrloop; elsif rising_edge(clk) then -- rising clock edge outx(3) <= outarray(7); jcloop: for j in 7 downto 1 loop outarray (j) := outarray(j-1); end loop jcloop; if (cmdarray(4) = "0011") then outarray(0) := in1reg3 / in2reg3; else outarray(0) := (others => '0'); end if; end if; end process cmd3reg; -- purpose: "0100" test the "resize" function cmd4reg: process (clk, rst_n) is variable tmpfp161, tmpfp162 : fp16; -- 16 bit fp number variable outarray : cry_type; -- array for output variable tmpcmd : STD_LOGIC_VECTOR (2 downto 0); begin -- process cmd1reg if rst_n = '0' then -- asynchronous reset (active low) outx(4) <= ( others => '0'); jrloop: for j in 0 to 7 loop outarray (j) := (others => '0'); end loop jrloop; elsif rising_edge(clk) then -- rising clock edge outx(4) <= outarray(7); jcloop: for j in 7 downto 1 loop outarray (j) := outarray(j-1); end loop jcloop; tmpcmd := to_slv (in2reg3 (in2reg3'low+2 downto in2reg3'low)); case tmpcmd is when "000" => tmpfp161 := resize ( arg => in1reg3, exponent_width => tmpfp161'high, fraction_width => -tmpfp161'low, denormalize_in => true, denormalize => false, round_style => round_zero); when "001" => tmpfp161 := resize ( arg => in1reg3,-- size_res => tmpfp161, exponent_width => tmpfp161'high, fraction_width => -tmpfp161'low, denormalize_in => false, denormalize => false); when "010" => tmpfp161 := resize ( arg => in1reg3, exponent_width => tmpfp161'high, fraction_width => -tmpfp161'low, denormalize_in => false, denormalize => false); when "011" => tmpfp161 := resize ( arg => in1reg3,-- size_res => tmpfp161, exponent_width => tmpfp161'high, fraction_width => -tmpfp161'low, denormalize_in => true, denormalize => false, round_style => round_inf); when "100" => tmpfp161 := resize ( arg => in1reg3, exponent_width => tmpfp161'high, fraction_width => -tmpfp161'low, denormalize_in => true, denormalize => false, round_style => round_neginf); when "101" => tmpfp161 := resize ( arg => in1reg3,-- size_res => tmpfp161, exponent_width => tmpfp161'high, fraction_width => -tmpfp161'low, denormalize_in => true, denormalize => false, check_error => false, round_style => round_zero); when "110" => tmpfp161 := resize ( arg => in1reg3, exponent_width => tmpfp161'high, fraction_width => -tmpfp161'low); when "111" => tmpfp161 := resize ( arg => in1reg3, exponent_width => tmpfp161'high, fraction_width => -tmpfp161'low-- size_res => tmpfp161 ); when others => null; end case; outarray(0)(-8 downto -23) := tmpfp161; outarray(0)(8 downto 6) := float(tmpcmd); outarray(0)(6 downto -7) := (others => '0'); end if; end process cmd4reg; -- purpose: "0101" Conversion function test cmd5reg: process (clk, rst_n) is variable uns : unsigned (15 downto 0); -- unsigned number variable s : signed (15 downto 0); -- signed number variable uf : ufixed (8 downto -7); -- unsigned fixed variable sf : sfixed (8 downto -7); -- signed fixed point variable outarray : cry_type; -- array for output variable tmpcmd : STD_LOGIC_VECTOR (2 downto 0); begin -- process cmd1reg if rst_n = '0' then -- asynchronous reset (active low) outx(5) <= ( others => '0'); jrloop: for j in 0 to 7 loop outarray (j) := (others => '0'); end loop jrloop; elsif rising_edge(clk) then -- rising clock edge outx(5) <= outarray(7); jcloop: for j in 7 downto 1 loop outarray (j) := outarray(j-1); end loop jcloop; tmpcmd := to_slv (in2reg3 (in2reg3'low+2 downto in2reg3'low)); case tmpcmd is when "000" => uns := to_unsigned (in1reg3, uns'length); outarray(0)(-8 downto -23) := float(std_logic_vector(uns)); when "001" => uns := to_unsigned (in1reg3, uns); outarray(0)(-8 downto -23) := float(std_logic_vector(uns)); when "010" => s := to_signed (in1reg3, s'length); outarray(0)(-8 downto -23) := float(std_logic_vector(s)); when "011" => s := to_signed (in1reg3, s); outarray(0)(-8 downto -23) := float(std_logic_vector(s)); when "100" => uf := to_ufixed (in1reg3, uf'high, uf'low); outarray(0)(-8 downto -23) := float(to_slv(uf)); when "101" => uf := to_ufixed (in1reg3, uf); outarray(0)(-8 downto -23) := float(to_slv(uf)); when "110" => sf := to_sfixed (in1reg3, sf'high, sf'low); outarray(0)(-8 downto -23) := float(to_slv(sf)); when "111" => sf := to_sfixed (in1reg3, sf); outarray(0)(-8 downto -23) := float(to_slv(sf)); when others => null; end case; outarray(0)(8 downto 6) := float(tmpcmd); outarray(0)(5 downto -7) := (others => '0'); end if; end process cmd5reg; -- purpose: "0110" to_float() cmd6reg: process (clk, rst_n) is variable uns : unsigned (15 downto 0); -- unsigned number variable s : signed (15 downto 0); -- signed number variable uf : ufixed (8 downto -7); -- unsigned fixed variable sf : sfixed (8 downto -7); -- signed fixed point variable outarray : cry_type; -- array for output variable tmpcmd : STD_LOGIC_VECTOR (2 downto 0); begin -- process cmd1reg if rst_n = '0' then -- asynchronous reset (active low) outx(6) <= ( others => '0'); jrloop: for j in 0 to 7 loop outarray (j) := (others => '0'); end loop jrloop; elsif rising_edge(clk) then -- rising clock edge outx(6) <= outarray(7); jcloop: for j in 7 downto 1 loop outarray (j) := outarray(j-1); end loop jcloop; tmpcmd := to_slv (in2reg3 (in2reg3'low+2 downto in2reg3'low)); case tmpcmd is when "000" => uns := UNSIGNED (to_slv (in1reg3(-8 downto -23))); outarray(0) := to_float(uns, 8, 23); when "001" => uns := UNSIGNED (to_slv (in1reg3(-8 downto -23))); outarray(0) := to_float(uns, in1reg3); when "010" => s := SIGNED (to_slv (in1reg3(-8 downto -23))); outarray(0) := to_float(s, 8, 23); when "011" => s := SIGNED (to_slv (in1reg3(-8 downto -23))); outarray(0) := to_float(s, in1reg3); when "100" => uf := to_ufixed (to_slv (in1reg3(-8 downto -23)), uf'high, uf'low); outarray(0) := to_float(uf, 8, 23); when "101" => uf := to_ufixed (to_slv (in1reg3(-8 downto -23)), uf); outarray(0) := to_float(uf, in1reg3); when "110" => sf := to_sfixed (to_slv (in1reg3(-8 downto -23)), sf'high, sf'low); outarray(0) := to_float(sf, 8, 23); when "111" => sf := to_sfixed (to_slv (in1reg3(-8 downto -23)), sf); outarray(0) := to_float(sf, in1reg3); when others => null; end case; end if; end process cmd6reg; -- purpose: "0111" mod function cmd7reg: process (clk, rst_n) is variable tmpuns : unsigned (31 downto 0); -- unsigned number variable outarray : cry_type; -- array for output begin -- process cmd1reg if rst_n = '0' then -- asynchronous reset (active low) outx(7) <= ( others => '0'); jrloop: for j in 0 to 7 loop outarray (j) := (others => '0'); end loop jrloop; elsif rising_edge(clk) then -- rising clock edge outx(7) <= outarray(7); jcloop: for j in 7 downto 1 loop outarray (j) := outarray(j-1); end loop jcloop; outarray(0) := in1reg3 mod in2reg3; end if; end process cmd7reg; -- purpose: "1000" rem function cmd8reg: process (clk, rst_n) is variable outarray : cry_type; -- array for output begin -- process cmd2reg if rst_n = '0' then -- asynchronous reset (active low) outx(8) <= ( others => '0'); jrloop: for j in 0 to 7 loop outarray (j) := (others => '0'); end loop jrloop; elsif rising_edge(clk) then -- rising clock edge outx(8) <= outarray(7); jcloop: for j in 7 downto 1 loop outarray (j) := outarray(j-1); end loop jcloop; outarray(0) := in1reg3 rem in2reg3; end if; end process cmd8reg; -- purpose: "1001" to_float (constants) test cmd9reg: process (clk, rst_n) is variable outarray : cry_type; -- array for output variable tmpcmd : STD_LOGIC_VECTOR (2 downto 0); begin -- process cmd2reg if rst_n = '0' then -- asynchronous reset (active low) outx(9) <= ( others => '0'); jrloop: for j in 0 to 7 loop outarray (j) := (others => '0'); end loop jrloop; elsif rising_edge(clk) then -- rising clock edge outx(9) <= outarray(7); jcloop: for j in 7 downto 1 loop outarray (j) := outarray(j-1); end loop jcloop;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -