2 -- Description: FPU package wich contains constants and functions needed in the FPU core
7 use ieee.std_logic_1164.all;
8 use ieee.std_logic_unsigned.all;
13 -- Data width of floating-point number. Deafult: 32
14 constant FP_WIDTH : integer := 32;
16 -- Data width of fraction. Deafult: 23
17 constant FRAC_WIDTH : integer := 23;
19 -- Data width of exponent. Deafult: 8
20 constant EXP_WIDTH : integer := 8;
23 constant ZERO_VECTOR: std_logic_vector(FP_WIDTH-2 downto 0) := (others => '0');
26 constant INF : std_logic_vector(FP_WIDTH-2 downto 0) := (FP_WIDTH-2 downto FP_WIDTH-2-EXP_WIDTH+1 => '1', others => '0');
28 -- QNaN (Quit Not a Number) FP format (without sign bit)
29 constant QNAN : std_logic_vector(FP_WIDTH-2 downto 0) := (FP_WIDTH-2 downto FP_WIDTH-2-EXP_WIDTH => '1', others => '0');
31 -- SNaN (Signaling Not a Number) FP format (without sign bit)
32 constant SNAN : std_logic_vector(FP_WIDTH-2 downto 0) := (FP_WIDTH-2 downto FP_WIDTH-2-EXP_WIDTH+1 => '1', 0 => '1', others => '0');
34 -- count the zeros starting from left
35 function count_l_zeros (signal s_vector: std_logic_vector) return std_logic_vector;
37 -- count the zeros starting from right
38 function count_r_zeros (signal s_vector: std_logic_vector) return std_logic_vector;
42 package body fpupack is
44 -- count the zeros starting from left
45 function count_l_zeros (signal s_vector: std_logic_vector) return std_logic_vector is
46 variable v_count : std_logic_vector(5 downto 0);
49 for i in s_vector'range loop
51 when '0' => v_count := v_count + "000001";
59 -- count the zeros starting from right
60 function count_r_zeros (signal s_vector: std_logic_vector) return std_logic_vector is
61 variable v_count : std_logic_vector(5 downto 0);
64 for i in 0 to s_vector'length-1 loop
66 when '0' => v_count := v_count + "000001";