📄 fpu_exceptions.vhd
字号:
------------------------------------------------------------------------- -------- FPU -------- Floating Point Unit (Double precision) -------- -------- Author: David Lundgren -------- davidklun@gmail.com -------- ----------------------------------------------------------------------------- -------- Copyright (C) 2009 David Lundgren -------- davidklun@gmail.com -------- -------- This source file may be used and distributed without -------- restriction provided that this copyright statement is not -------- removed from the file and that any derivative work contains -------- the original copyright notice and the associated disclaimer.-------- -------- THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY -------- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -------- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -------- FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR -------- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -------- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -------- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE -------- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -------- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -------- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -------- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -------- OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -------- POSSIBILITY OF SUCH DAMAGE. -------- ------------------------------------------------------------------------- LIBRARY ieee; USE ieee.std_logic_1164.all; USE ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; use ieee.std_logic_misc.all; ENTITY fpu_exceptions IS PORT( clk, rst, enable : IN std_logic; rmode : IN std_logic_vector (1 DOWNTO 0); opa, opb, in_except : IN std_logic_vector (63 DOWNTO 0); exponent_in : IN std_logic_vector (11 DOWNTO 0); mantissa_in : IN std_logic_vector (1 DOWNTO 0); fpu_op : IN std_logic_vector (2 DOWNTO 0); out_fp : OUT std_logic_vector (63 DOWNTO 0); ex_enable, underflow, overflow, inexact : OUT std_logic; exception, invalid : OUT std_logic ); END fpu_exceptions; architecture rtl of fpu_exceptions is signal in_et_zero : std_logic; signal opa_et_zero : std_logic; signal opb_et_zero : std_logic; signal add : std_logic; signal subtract : std_logic; signal multiply : std_logic; signal divide : std_logic; signal opa_QNaN : std_logic; signal opb_QNaN : std_logic; signal opa_SNaN : std_logic; signal opb_SNaN : std_logic; signal opa_pos_inf : std_logic; signal opb_pos_inf : std_logic; signal opa_neg_inf : std_logic; signal opb_neg_inf : std_logic; signal opa_inf : std_logic; signal opb_inf : std_logic; signal NaN_input : std_logic; signal SNaN_input : std_logic; signal a_NaN : std_logic; signal div_by_0 : std_logic; signal div_0_by_0 : std_logic; signal div_inf_by_inf : std_logic; signal div_by_inf : std_logic; signal mul_0_by_inf : std_logic; signal mul_inf : std_logic; signal div_inf : std_logic; signal add_inf : std_logic; signal sub_inf : std_logic; signal addsub_inf_invalid : std_logic; signal addsub_inf : std_logic; signal out_inf_trigger : std_logic; signal out_pos_inf : std_logic; signal out_neg_inf : std_logic; signal round_nearest : std_logic; signal round_to_zero : std_logic; signal round_to_pos_inf : std_logic; signal round_to_neg_inf : std_logic; signal inf_round_down_trigger : std_logic; signal mul_uf : std_logic; signal div_uf : std_logic; signal underflow_trigger : std_logic; signal invalid_trigger : std_logic; signal overflow_trigger : std_logic; signal inexact_trigger : std_logic; signal except_trigger : std_logic; signal enable_trigger : std_logic; signal NaN_out_trigger : std_logic; signal SNaN_trigger : std_logic; signal exp_2047 : std_logic_vector(10 downto 0); signal exp_2046 : std_logic_vector(10 downto 0); signal NaN_output_0 : std_logic_vector(62 downto 0); signal NaN_output : std_logic_vector(62 downto 0); signal mantissa_max : std_logic_vector(51 downto 0); signal inf_round_down : std_logic_vector(62 downto 0); signal out_inf : std_logic_vector(62 downto 0); signal out_0 : std_logic_vector(63 downto 0); signal out_1 : std_logic_vector(63 downto 0); signal out_2 : std_logic_vector(63 downto 0); begin exp_2047 <= "11111111111"; exp_2046 <= "11111111110"; mantissa_max <= "1111111111111111111111111111111111111111111111111111"; process begin wait until clk'event and clk = '1'; if (rst = '1') then in_et_zero <= '0'; opa_et_zero <= '0'; opb_et_zero <= '0'; add <= '0'; subtract <= '0'; multiply <= '0'; divide <= '0'; opa_QNaN <= '0'; opb_QNaN <= '0'; opa_SNaN <= '0'; opb_SNaN <= '0'; opa_pos_inf <= '0'; opb_pos_inf <= '0'; opa_neg_inf <= '0'; opb_neg_inf <= '0'; opa_inf <= '0'; opb_inf <= '0'; NaN_input <= '0'; SNaN_input <= '0'; a_NaN <= '0'; div_by_0 <= '0'; div_0_by_0 <= '0'; div_inf_by_inf <= '0'; div_by_inf <= '0'; mul_0_by_inf <= '0'; mul_inf <= '0'; div_inf <= '0'; add_inf <= '0'; sub_inf <= '0'; addsub_inf_invalid <= '0'; addsub_inf <= '0'; out_inf_trigger <= '0'; out_pos_inf <= '0'; out_neg_inf <= '0'; round_nearest <= '0'; round_to_zero <= '0'; round_to_pos_inf <= '0'; round_to_neg_inf <= '0'; inf_round_down_trigger <= '0'; mul_uf <= '0'; div_uf <= '0'; underflow_trigger <= '0'; invalid_trigger <= '0'; overflow_trigger <= '0'; inexact_trigger <= '0'; except_trigger <= '0'; enable_trigger <= '0'; NaN_out_trigger <= '0'; SNaN_trigger <= '0'; NaN_output_0 <= (others =>'0'); NaN_output <= (others =>'0'); inf_round_down <= (others =>'0'); out_inf <= (others =>'0'); out_0 <= (others =>'0'); out_1 <= (others =>'0'); out_2 <= (others =>'0'); elsif (enable = '1') then if or_reduce(in_except(62 downto 0)) = '0' then in_et_zero <= '1'; else in_et_zero <= '0'; end if; if or_reduce(opa(62 downto 0)) = '0' then opa_et_zero <= '1'; else opa_et_zero <= '0'; end if; if or_reduce(opb(62 downto 0)) = '0' then opb_et_zero <= '1'; else opb_et_zero <= '0'; end if; if fpu_op = "000" then add <= '1'; else add <= '0'; end if; if fpu_op = "001" then subtract <= '1'; else subtract <= '0'; end if; if fpu_op = "010" then multiply <= '1'; else multiply <= '0'; end if; if fpu_op = "011" then divide <= '1'; else divide <= '0'; end if; if opa(62 downto 52) = "11111111111" and or_reduce(opa(51 downto 0)) = '1' and opa(51) = '1' then opa_QNaN <= '1'; else opa_QNaN <= '0'; end if; if opb(62 downto 52) = "11111111111" and or_reduce(opb(51 downto 0)) = '1' and opb(51) = '1' then opb_QNaN <= '1'; else opb_QNaN <= '0'; end if; if opa(62 downto 52) = "11111111111" and or_reduce(opa(51 downto 0)) = '1' and opa(51) = '0' then opa_SNaN <= '1'; else opa_SNaN <= '0'; end if; if opb(62 downto 52) = "11111111111" and or_reduce(opb(51 downto 0)) = '1' and opb(51) = '0' then opb_SNaN <= '1'; else opb_SNaN <= '0'; end if; if opa(62 downto 52) = "11111111111" and or_reduce(opa(51 downto 0)) = '0' and opa(63) = '0' then opa_pos_inf <= '1'; else opa_pos_inf <= '0'; end if; if opb(62 downto 52) = "11111111111" and or_reduce(opb(51 downto 0)) = '0' and opb(63) = '0' then opb_pos_inf <= '1'; else opb_pos_inf <= '0'; end if; if opa(62 downto 52) = "11111111111" and or_reduce(opa(51 downto 0)) = '0' and opa(63) = '1' then opa_neg_inf <= '1';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -