OpenCores
URL https://opencores.org/ocsvn/fpu_double/fpu_double/trunk

Subversion Repositories fpu_double

[/] [fpu_double/] [trunk/] [fpu_sub.vhd] - Diff between revs 5 and 8

Only display areas with differences | Details | Blame | View Log

Rev 5 Rev 8
---------------------------------------------------------------------
---------------------------------------------------------------------
----                                                             ----
----                                                             ----
----  FPU                                                        ----
----  FPU                                                        ----
----  Floating Point Unit (Double precision)                     ----
----  Floating Point Unit (Double precision)                     ----
----                                                             ----
----                                                             ----
----  Author: David Lundgren                                     ----
----  Author: David Lundgren                                     ----
----          davidklun@gmail.com                                ----
----          davidklun@gmail.com                                ----
----                                                             ----
----                                                             ----
---------------------------------------------------------------------
---------------------------------------------------------------------
----                                                             ----
----                                                             ----
---- Copyright (C) 2009 David Lundgren                           ----
---- Copyright (C) 2009 David Lundgren                           ----
----                  davidklun@gmail.com                        ----
----                  davidklun@gmail.com                        ----
----                                                             ----
----                                                             ----
---- This source file may be used and distributed without        ----
---- This source file may be used and distributed without        ----
---- restriction provided that this copyright statement is not   ----
---- restriction provided that this copyright statement is not   ----
---- removed from the file and that any derivative work contains ----
---- removed from the file and that any derivative work contains ----
---- the original copyright notice and the associated disclaimer.----
---- the original copyright notice and the associated disclaimer.----
----                                                             ----
----                                                             ----
----     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ----
----     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ----
---- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ----
---- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ----
---- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ----
---- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ----
---- FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ----
---- FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ----
---- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ----
---- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ----
---- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ----
---- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ----
---- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ----
---- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ----
---- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ----
---- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ----
---- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ----
---- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ----
---- LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ----
---- LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ----
---- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ----
---- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ----
---- OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ----
---- OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ----
---- POSSIBILITY OF SUCH DAMAGE.                                 ----
---- POSSIBILITY OF SUCH DAMAGE.                                 ----
----                                                             ----
----                                                             ----
---------------------------------------------------------------------
---------------------------------------------------------------------
 
 
        LIBRARY ieee;
        LIBRARY ieee;
        USE ieee.std_logic_1164.all;
        USE ieee.std_logic_1164.all;
        USE ieee.std_logic_arith.all;
        USE ieee.std_logic_arith.all;
        use ieee.std_logic_unsigned.all;
        use ieee.std_logic_unsigned.all;
        use ieee.std_logic_misc.all;
        use ieee.std_logic_misc.all;
        library work;
        library work;
        use work.fpupack.all;
        use work.fpupack.all;
 
 
        ENTITY fpu_sub IS
        ENTITY fpu_sub IS
 
 
   PORT(
   PORT(
      clk : IN     std_logic;
      clk : IN     std_logic;
      rst : IN     std_logic;
      rst : IN     std_logic;
      enable  : IN     std_logic;
      enable  : IN     std_logic;
      opa : IN     std_logic_vector (63 DOWNTO 0);
      opa : IN     std_logic_vector (63 DOWNTO 0);
      opb : IN     std_logic_vector (63 DOWNTO 0);
      opb : IN     std_logic_vector (63 DOWNTO 0);
      fpu_op : IN     std_logic_vector (2 DOWNTO 0);
      fpu_op : IN     std_logic_vector (2 DOWNTO 0);
      sign : OUT    std_logic;
      sign : OUT    std_logic;
      diff_2 : OUT    std_logic_vector (55 DOWNTO 0);
      diff_2 : OUT    std_logic_vector (55 DOWNTO 0);
      exponent_2 : OUT    std_logic_vector (10 DOWNTO 0)
      exponent_2 : OUT    std_logic_vector (10 DOWNTO 0)
   );
   );
 
 
        -- Declarations
        -- Declarations
 
 
        END fpu_sub;
        END fpu_sub;
 
 
 
 
        architecture rtl of fpu_sub is
        architecture rtl of fpu_sub is
 
 
        signal   fpu_op_add : std_logic;
        signal   fpu_op_add : std_logic;
        signal   diff_shift : std_logic_vector(5 downto 0);
        signal   diff_shift : std_logic_vector(5 downto 0);
        signal   diff_shift_2 : std_logic_vector(5 downto 0);
        signal   diff_shift_2 : std_logic_vector(5 downto 0);
        signal   exponent_a : std_logic_vector(10 downto 0);
        signal   exponent_a : std_logic_vector(10 downto 0);
        signal   exponent_b : std_logic_vector(10 downto 0);
        signal   exponent_b : std_logic_vector(10 downto 0);
        signal   mantissa_a : std_logic_vector(51 downto 0);
        signal   mantissa_a : std_logic_vector(51 downto 0);
        signal   mantissa_b : std_logic_vector(51 downto 0);
        signal   mantissa_b : std_logic_vector(51 downto 0);
        signal   expa_gt_expb : std_logic;
        signal   expa_gt_expb : std_logic;
        signal   expa_et_expb : std_logic;
        signal   expa_et_expb : std_logic;
        signal   mana_gtet_manb : std_logic;
        signal   mana_gtet_manb : std_logic;
        signal   a_gtet_b : std_logic;
        signal   a_gtet_b : std_logic;
        signal   exponent_small : std_logic_vector(10 downto 0);
        signal   exponent_small : std_logic_vector(10 downto 0);
        signal   exponent_large : std_logic_vector(10 downto 0);
        signal   exponent_large : std_logic_vector(10 downto 0);
        signal   mantissa_small : std_logic_vector(51 downto 0);
        signal   mantissa_small : std_logic_vector(51 downto 0);
        signal   mantissa_large : std_logic_vector(51 downto 0);
        signal   mantissa_large : std_logic_vector(51 downto 0);
        signal   small_is_denorm : std_logic;
        signal   small_is_denorm : std_logic;
        signal   large_is_denorm : std_logic;
        signal   large_is_denorm : std_logic;
        signal   large_norm_small_denorm : std_logic;
        signal   large_norm_small_denorm : std_logic;
        signal   small_is_nonzero : std_logic;
        signal   small_is_nonzero : std_logic;
        signal   exponent_diff : std_logic_vector(10 downto 0);
        signal   exponent_diff : std_logic_vector(10 downto 0);
        signal   minuend : std_logic_vector(54 downto 0);
        signal   minuend : std_logic_vector(54 downto 0);
        signal   subtrahend : std_logic_vector(54 downto 0);
        signal   subtrahend : std_logic_vector(54 downto 0);
        signal   subtra_shift : std_logic_vector(54 downto 0);
        signal   subtra_shift : std_logic_vector(54 downto 0);
        signal   subtra_shift_nonzero : std_logic;
        signal   subtra_shift_nonzero : std_logic;
        signal   subtra_fraction_enable : std_logic;
        signal   subtra_fraction_enable : std_logic;
        signal   subtra_shift_2 : std_logic_vector(54 downto 0);
        signal   subtra_shift_2 : std_logic_vector(54 downto 0);
        signal   subtra_shift_3 : std_logic_vector(54 downto 0);
        signal   subtra_shift_3 : std_logic_vector(54 downto 0);
        signal   diff : std_logic_vector(54 downto 0);
        signal   diff : std_logic_vector(54 downto 0);
        signal   diffshift_gt_exponent : std_logic;
        signal   diffshift_gt_exponent : std_logic;
        signal   diffshift_et_55 : std_logic; -- when the difference = 0
        signal   diffshift_et_55 : std_logic; -- when the difference = 0
        signal   diff_1 : std_logic_vector(54 downto 0);
        signal   diff_1 : std_logic_vector(54 downto 0);
        signal   exponent : std_logic_vector(10 downto 0);
        signal   exponent : std_logic_vector(10 downto 0);
        signal   in_norm_out_denorm : std_logic;
        signal   in_norm_out_denorm : std_logic;
 
 
        begin
        begin
 
 
        subtra_shift_nonzero <= or_reduce(subtra_shift);
        subtra_shift_nonzero <= or_reduce(subtra_shift);
        subtra_fraction_enable <= small_is_nonzero and not subtra_shift_nonzero;
        subtra_fraction_enable <= small_is_nonzero and not subtra_shift_nonzero;
        subtra_shift_2 <= "0000000000000000000000000000000000000000000000000000001";
        subtra_shift_2 <= "0000000000000000000000000000000000000000000000000000001";
        in_norm_out_denorm <= or_reduce(exponent_large) and not or_reduce(exponent);
        in_norm_out_denorm <= or_reduce(exponent_large) and not or_reduce(exponent);
        fpu_op_add <= '1' when fpu_op = "000" else '0';
        fpu_op_add <= '1' when fpu_op = "000" else '0';
 
 
process
process
        begin
        begin
        wait until clk'event and clk = '1';
        wait until clk'event and clk = '1';
                if (rst = '1') then
                if (rst = '1') then
                        exponent_a <= (others =>'0');
                        exponent_a <= (others =>'0');
                        exponent_b <= (others =>'0');
                        exponent_b <= (others =>'0');
                        mantissa_a <= (others =>'0');
                        mantissa_a <= (others =>'0');
                        mantissa_b <= (others =>'0');
                        mantissa_b <= (others =>'0');
                        expa_gt_expb <= '0';
                        expa_gt_expb <= '0';
                        expa_et_expb <= '0';
                        expa_et_expb <= '0';
                        mana_gtet_manb <= '0';
                        mana_gtet_manb <= '0';
                        a_gtet_b <= '0';
                        a_gtet_b <= '0';
                        exponent_small  <= (others =>'0');
                        exponent_small  <= (others =>'0');
                        exponent_large  <= (others =>'0');
                        exponent_large  <= (others =>'0');
                        mantissa_small  <= (others =>'0');
                        mantissa_small  <= (others =>'0');
                        mantissa_large  <= (others =>'0');
                        mantissa_large  <= (others =>'0');
                        sign <= '0';
                        sign <= '0';
                        small_is_denorm <= '0';
                        small_is_denorm <= '0';
                        large_is_denorm <= '0';
                        large_is_denorm <= '0';
                        large_norm_small_denorm <= '0';
                        large_norm_small_denorm <= '0';
                        small_is_nonzero <= '0';
                        small_is_nonzero <= '0';
                        exponent_diff <= (others =>'0');
                        exponent_diff <= (others =>'0');
                        minuend <= (others =>'0');
                        minuend <= (others =>'0');
                        subtrahend <= (others =>'0');
                        subtrahend <= (others =>'0');
                        subtra_shift <= (others =>'0');
                        subtra_shift <= (others =>'0');
                        subtra_shift_3 <= (others =>'0');
                        subtra_shift_3 <= (others =>'0');
 
                        diff_shift <= (others =>'0');
                        diff_shift_2 <= (others =>'0');
                        diff_shift_2 <= (others =>'0');
                        diff <= (others =>'0');
                        diff <= (others =>'0');
                        diffshift_gt_exponent <= '0';
                        diffshift_gt_exponent <= '0';
                        diffshift_et_55 <= '0';
                        diffshift_et_55 <= '0';
                        diff_1 <= (others =>'0');
                        diff_1 <= (others =>'0');
                        exponent <= (others =>'0');
                        exponent <= (others =>'0');
                        exponent_2 <= (others =>'0');
                        exponent_2 <= (others =>'0');
                        diff_2 <= (others =>'0');
                        diff_2 <= (others =>'0');
                elsif (enable = '1') then
                elsif (enable = '1') then
                        exponent_a <= opa(62 downto 52);
                        exponent_a <= opa(62 downto 52);
                        exponent_b <= opb(62 downto 52);
                        exponent_b <= opb(62 downto 52);
                        mantissa_a <= opa(51 downto 0);
                        mantissa_a <= opa(51 downto 0);
                        mantissa_b <= opb(51 downto 0);
                        mantissa_b <= opb(51 downto 0);
                        if (exponent_a > exponent_b) then
                        if (exponent_a > exponent_b) then
                                expa_gt_expb <= '1';
                                expa_gt_expb <= '1';
                        else
                        else
                                expa_gt_expb <= '0';
                                expa_gt_expb <= '0';
                        end if;
                        end if;
                        if (exponent_a = exponent_b) then
                        if (exponent_a = exponent_b) then
                                expa_et_expb <= '1';
                                expa_et_expb <= '1';
                        else
                        else
                                expa_et_expb <= '0';
                                expa_et_expb <= '0';
                        end if;
                        end if;
                        if (mantissa_a >= mantissa_b) then
                        if (mantissa_a >= mantissa_b) then
                                mana_gtet_manb <= '1';
                                mana_gtet_manb <= '1';
                        else
                        else
                                mana_gtet_manb <= '0';
                                mana_gtet_manb <= '0';
                        end if;
                        end if;
                        a_gtet_b <= expa_gt_expb or (expa_et_expb and mana_gtet_manb);
                        a_gtet_b <= expa_gt_expb or (expa_et_expb and mana_gtet_manb);
                        if (a_gtet_b = '1') then
                        if (a_gtet_b = '1') then
                                exponent_small <= exponent_b;
                                exponent_small <= exponent_b;
                                exponent_large <= exponent_a;
                                exponent_large <= exponent_a;
                                mantissa_small <= mantissa_b;
                                mantissa_small <= mantissa_b;
                                mantissa_large <= mantissa_a;
                                mantissa_large <= mantissa_a;
                                sign <= opa(63);
                                sign <= opa(63);
                        else
                        else
                                exponent_small <= exponent_a;
                                exponent_small <= exponent_a;
                                exponent_large <= exponent_b;
                                exponent_large <= exponent_b;
                                mantissa_small <= mantissa_a;
                                mantissa_small <= mantissa_a;
                                mantissa_large <= mantissa_b;
                                mantissa_large <= mantissa_b;
                                sign <= (not opb(63)) xor fpu_op_add;
                                sign <= (not opb(63)) xor fpu_op_add;
                        end if;
                        end if;
                        if (exponent_small > 0) then
                        if (exponent_small > 0) then
                                small_is_denorm <= '0';
                                small_is_denorm <= '0';
                        else
                        else
                                small_is_denorm <= '1';
                                small_is_denorm <= '1';
                        end if;
                        end if;
                        if (exponent_large > 0) then
                        if (exponent_large > 0) then
                                large_is_denorm <= '0';
                                large_is_denorm <= '0';
                        else
                        else
                                large_is_denorm <= '1';
                                large_is_denorm <= '1';
                        end if;
                        end if;
                        if (small_is_denorm = '1' and large_is_denorm = '0') then
                        if (small_is_denorm = '1' and large_is_denorm = '0') then
                                large_norm_small_denorm <= '1';
                                large_norm_small_denorm <= '1';
                        else
                        else
                                large_norm_small_denorm <= '0';
                                large_norm_small_denorm <= '0';
                        end if;
                        end if;
                        small_is_nonzero <= (not small_is_denorm) or or_reduce(mantissa_small);
                        small_is_nonzero <= (not small_is_denorm) or or_reduce(mantissa_small);
                        exponent_diff <= exponent_large - exponent_small - large_norm_small_denorm;
                        exponent_diff <= exponent_large - exponent_small - large_norm_small_denorm;
                        minuend <= not large_is_denorm & mantissa_large & "00";
                        minuend <= not large_is_denorm & mantissa_large & "00";
                        subtrahend <= not small_is_denorm & mantissa_small & "00";
                        subtrahend <= not small_is_denorm & mantissa_small & "00";
                        subtra_shift <= shr(subtrahend,  exponent_diff);
                        subtra_shift <= shr(subtrahend,  exponent_diff);
                        if (subtra_fraction_enable = '1') then
                        if (subtra_fraction_enable = '1') then
                                subtra_shift_3 <= subtra_shift_2;
                                subtra_shift_3 <= subtra_shift_2;
                        else
                        else
                                subtra_shift_3 <= subtra_shift;
                                subtra_shift_3 <= subtra_shift;
                        end if;
                        end if;
                        diff <= minuend - subtra_shift_3;
                        diff <= minuend - subtra_shift_3;
                        diff_shift <= count_l_zeros(diff(54 downto 0));
                        diff_shift <= count_l_zeros(diff(54 downto 0));
                        diff_shift_2 <= diff_shift;
                        diff_shift_2 <= diff_shift;
                        if (diff_shift_2 > exponent_large) then
                        if (diff_shift_2 > exponent_large) then
                                diffshift_gt_exponent <= '1';
                                diffshift_gt_exponent <= '1';
                        else
                        else
                                diffshift_gt_exponent <= '0';
                                diffshift_gt_exponent <= '0';
                        end if;
                        end if;
                        if (diff_shift_2 = "0110111") then -- 55
                        if (diff_shift_2 = "0110111") then -- 55
                                diffshift_et_55 <= '1';
                                diffshift_et_55 <= '1';
                        else
                        else
                                diffshift_et_55 <= '0';
                                diffshift_et_55 <= '0';
                        end if;
                        end if;
                        if (diffshift_gt_exponent = '1') then
                        if (diffshift_gt_exponent = '1') then
                                diff_1 <= shl(diff, exponent_large);
                                diff_1 <= shl(diff, exponent_large);
                                exponent <= "00000000000";
                                exponent <= "00000000000";
                        else
                        else
                                diff_1 <= shl(diff, diff_shift_2);
                                diff_1 <= shl(diff, diff_shift_2);
                                exponent <= exponent_large - diff_shift_2;
                                exponent <= exponent_large - diff_shift_2;
                        end if;
                        end if;
                        if (diffshift_et_55 = '1') then
                        if (diffshift_et_55 = '1') then
                                exponent_2 <= "00000000000";
                                exponent_2 <= "00000000000";
                        else
                        else
                                exponent_2 <=  exponent;
                                exponent_2 <=  exponent;
                        end if;
                        end if;
                        if (in_norm_out_denorm = '1') then
                        if (in_norm_out_denorm = '1') then
                                diff_2 <= '0' & shr(diff_1,conv_std_logic_vector('1', 55));
                                diff_2 <= '0' & shr(diff_1,conv_std_logic_vector('1', 55));
                        else
                        else
                                diff_2 <= '0' & diff_1;
                                diff_2 <= '0' & diff_1;
                        end if;
                        end if;
                end if;
                end if;
        end process;
        end process;
 
 
        end rtl;
        end rtl;
 
 
 
 
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.