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

Subversion Repositories raytrac

[/] [raytrac/] [branches/] [fp/] [fadd32.vhd] - Diff between revs 118 and 119

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 118 Rev 119
Line 1... Line 1...
------------------------------------------------
------------------------------------------------
--! @file ema32x2.vhd
--! @file fadd32.vhd
--! @brief RayTrac Floating Point Adder  
--! @brief RayTrac Floating Point Adder  
--! @author Julián Andrés Guarín Reyes
--! @author Julián Andrés Guarín Reyes
--------------------------------------------------
--------------------------------------------------
 
 
 
 
-- RAYTRAC (FP BRANCH)
-- RAYTRAC (FP BRANCH)
-- Author Julian Andres Guarin
-- Author Julian Andres Guarin
-- ema32x2.vhd
-- fadd32.vhd
-- This file is part of raytrac.
-- This file is part of raytrac.
-- 
-- 
--     raytrac is free software: you can redistribute it and/or modify
--     raytrac is free software: you can redistribute it and/or modify
--     it under the terms of the GNU General Public License as published by
--     it under the terms of the GNU General Public License as published by
--     the Free Software Foundation, either version 3 of the License, or
--     the Free Software Foundation, either version 3 of the License, or
Line 25... Line 25...
 
 
library ieee;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_arith.all;
 
library lpm;
 
use lpm.all;
 
 
--! Esta entidad recibe dos n&uacutemeros en formato punto flotante IEEE 754, de precision simple y devuelve las mantissas signadas y corridas, y el exponente correspondiente al resultado antes de normalizarlo al formato float. 
--! Esta entidad recibe dos n&uacutemeros en formato punto flotante IEEE 754, de precision simple y devuelve las mantissas signadas y corridas, y el exponente correspondiente al resultado antes de normalizarlo al formato float. 
--!\nLas 2 mantissas y el exponente entran despues a la entidad add2 que suma las mantissas y entrega el resultado en formato IEEE 754.
--!\nLas 2 mantissas y el exponente entran despues a la entidad add2 que suma las mantissas y entrega el resultado en formato IEEE 754.
entity ema32x2 is
entity fadd32 is
        port (
        port (
                clk,dpc         : in std_logic;
                clk,dpc         : in std_logic;
                a32,b32         : in std_logic_vector (31 downto 0);
                a32,b32         : in std_logic_vector (31 downto 0);
                c32                     : out std_logic_vector(31 downto 0)
                c32                     : out std_logic_vector(31 downto 0)
        );
        );
end ema32x2;
end fadd32;
 
 
architecture ema32x2_arch of ema32x2 is
architecture fadd32_arch of fadd32 is
 
 
        component lpm_mult
        component lpm_mult
        generic (
        generic (
                lpm_hint                        : string;
                lpm_hint                        : string;
                lpm_representation      : string;
                lpm_representation      : string;
Line 57... Line 58...
        );
        );
        end component;
        end component;
 
 
        signal s1zero                                                                                                           : std_logic;
        signal s1zero                                                                                                           : std_logic;
        signal s1delta                                                                                                          : std_logic_vector(5 downto 0);
        signal s1delta                                                                                                          : std_logic_vector(5 downto 0);
        signal s0delta,s1exp,s2exp,s3exp,s4exp,s5exp,s5factor,s6exp,s6factor: std_logic_vector(7 downto 0);
        signal s0delta,s1exp,s2exp,s3exp,s4exp,s5exp,s6exp,s5factor,s6factor,s7exp,s7factor     : std_logic_vector(7 downto 0);
        signal s1shifter,s5factorhot9                                                                           : std_logic_vector(8 downto 0);
        signal s1shifter,s5factorhot9,s6factorhot9                                                                                      : std_logic_vector(8 downto 0);
        signal s1pl,s5pl                                                                                                        : std_logic_vector(17 downto 0);
        signal s1pl,s6pl                                                                                                                                        : std_logic_vector(17 downto 0);
        signal s5postshift,s6postshift                                                                          : std_logic_vector(22 downto 0);
        signal s6postshift,s7postshift                                                                                                          : std_logic_vector(22 downto 0);
        signal s1umantshift,s1umantfixed,s1postshift,s1xorslab,s2xorslab        : std_logic_vector(23 downto 0);
        signal s1umantshift,s1umantfixed,s1postshift,s1xorslab,s2xorslab        : std_logic_vector(23 downto 0);
        signal s2umantshift,s2mantfixed,s3mantfixed,s3mantshift,s4xorslab       : std_logic_vector(24 downto 0);
        signal s2umantshift,s2mantfixed,s3mantfixed,s3mantshift,s4xorslab       : std_logic_vector(24 downto 0);
        signal s5factorhot25                                                                                            : std_logic_vector(24 downto 0);
        signal s5factorhot25                                                                                            : std_logic_vector(24 downto 0);
        signal s4sresult,s5result,s6result                                                                      : std_logic_vector(25 downto 0); -- Signed mantissa result
        signal s4sresult,s5result,s6result,s7result                                                                                     : std_logic_vector(25 downto 0); -- Signed mantissa result
        signal s1ph,s5ph                                                                                                        : std_logic_vector(26 downto 0);
        signal s1ph,s6ph                                                                                                                                        : std_logic_vector(26 downto 0);
        signal s0a,s0b                                                                                                          : std_logic_vector(31 downto 0); -- Float 32 bit 
        signal s0a,s0b                                                                                                          : std_logic_vector(31 downto 0); -- Float 32 bit 
 
 
begin
begin
 
 
        process (clk)
        process (clk)
Line 86... Line 87...
                        if (s0b(30 downto 23)&s0a(30 downto 23))=x"0000" then
                        if (s0b(30 downto 23)&s0a(30 downto 23))=x"0000" then
                                s1zero <= '0';
                                s1zero <= '0';
                        else
                        else
                                s1zero <= '1';
                                s1zero <= '1';
                        end if;
                        end if;
                        s1delta <= s0delta(7) & (s0delta(7) xor s0delta(4))&(s0delta(7) xor s0delta(4)) & s0delta(2 downto 0);
                        s1delta <= s0delta(7) & (s0delta(7) xor s0delta(4))&(s0delta(7) xor s0delta(3)) & s0delta(2 downto 0);
                        case s0delta(7) is
                        case s0delta(7) is
                                when '1'  =>
                                when '1'  =>
                                        s1exp <= s0b(30 downto 23);
                                        s1exp <= s0b(30 downto 23);
                                        s1umantshift <= s0a(31)&s0a(22 downto 0);
                                        s1umantshift <= s0a(31)&s0a(22 downto 0);
                                        s1umantfixed <= s0b(31)&s0b(22 downto 0);
                                        s1umantfixed <= s0b(31)&s0b(22 downto 0);
Line 113... Line 114...
                        --! Etapa2: Signar la mantissa denormalizada.
                        --! Etapa2: Signar la mantissa denormalizada.
                        s3mantfixed <= s2mantfixed;
                        s3mantfixed <= s2mantfixed;
                        s3mantshift <= s2umantshift(24)&         (  (      s2umantshift(23 downto 0)  xor s2xorslab)   + ( x"00000"&"000"&s2umantshift(24)  )   );
                        s3mantshift <= s2umantshift(24)&         (  (      s2umantshift(23 downto 0)  xor s2xorslab)   + ( x"00000"&"000"&s2umantshift(24)  )   );
                        s3exp           <= s2exp;
                        s3exp           <= s2exp;
 
 
                        --! Etapa 3: Etapa 3 Realizar la suma, quitar el signo de la mantissa y codificar el corrimiento hacia la izquierda.
                        --! Etapa 3: Etapa 3 Realizar la suma, entre la mantissa corrida y la fija.
                        s4sresult       <= (s3mantshift(24)&s3mantshift)+(s3mantfixed(24)&s3mantfixed);
                        s4sresult       <= (s3mantshift(24)&s3mantshift)+(s3mantfixed(24)&s3mantfixed);
                        s4exp           <= s3exp;
                        s4exp           <= s3exp;
 
 
                        --! Etapa 4: Quitar el signo a la mantissa resultante.
                        --! Etapa 4: Quitar el signo a la mantissa resultante.
                        s5result        <= s4sresult(25)&((s4sresult(24 downto 0) xor s4xorslab)  +(x"000000"&s4sresult(25)));
                        s5result        <= s4sresult(25)&((s4sresult(24 downto 0) xor s4xorslab)  +(x"000000"&s4sresult(25)));
Line 126... Line 127...
 
 
                        --! Etapa 5: Codificar el corrimiento para la normalizacion de la mantissa resultante.
                        --! Etapa 5: Codificar el corrimiento para la normalizacion de la mantissa resultante.
                        s6result                <= s5result;
                        s6result                <= s5result;
                        s6exp                   <= s5exp;
                        s6exp                   <= s5exp;
                        s6factor                <= s5factor;
                        s6factor                <= s5factor;
                        s6postshift             <= s5postshift;
                        s6factorhot9    <= s5factorhot9;
 
 
                        --! Etapa 6: Entregar el resultado.
                        --! Etapa 6: Ejecutar el corrimiento de la mantissa.
                        c32(31)                         <= s6result(25);
                        s7result                <= s6result;
                        c32(30 downto 23)       <= s6exp+s6factor+x"ff";
                        s7exp                   <= s6exp;
                        case s6factor(4 downto 3) is
                        s7factor                <= s6factor+x"ff";
                                when "01"       => c32(22 downto 0) <= s6postshift(14 downto 00)&x"00";
                        s7postshift             <= s6postshift;
                                when "10"       => c32(22 downto 0) <= s6postshift(06 downto 00)&x"0000";
 
                                when others => c32(22 downto 0)  <= s6postshift;
                        --! Etapa 7: Entregar el resultado.
 
                        c32(31)                         <= s7result(25);
 
                        c32(30 downto 23)       <= s7exp+s7factor;
 
                        case s7factor(4 downto 3) is
 
                                when "01"       => c32(22 downto 0) <= s7postshift(14 downto 00)&x"00";
 
                                when "10"       => c32(22 downto 0) <= s7postshift(06 downto 00)&x"0000";
 
                                when others => c32(22 downto 0)  <= s7postshift;
                        end case;
                        end case;
                end if;
                end if;
        end process;
        end process;
        --! Combinatorial gremlin, Etapa 0 el corrimiento de la mantissa con menor exponente y reorganiza los operandos,\n
        --! Combinatorial gremlin, Etapa 0 el corrimiento de la mantissa con menor exponente y reorganiza los operandos,\n
        --! si el mayor es b, intercambia las posici&oacute;n si el mayor es a las posiciones la mantiene. 
        --! si el mayor es b, intercambia las posici&oacute;n si el mayor es a las posiciones la mantiene. 
Line 177... Line 184...
 
 
        --! Combinatorial Gremlin, Etapa 5: Codificar el factor de normalizacion de la mantissa resultante.
        --! Combinatorial Gremlin, Etapa 5: Codificar el factor de normalizacion de la mantissa resultante.
        normalizerdecodeshift:
        normalizerdecodeshift:
        process (s5result,s5factorhot25)
        process (s5result,s5factorhot25)
        begin
        begin
                s5factor<=(others => '0');
                s5factor <= x"00";
                s5factorhot25 <= (others => '0');
                s5factorhot25 <= '0'&x"000000";
                for i in 24 downto 0 loop
                for i in 24 downto 0 loop
                        if s5result(i)='1' then
                        if s5result(i)='1' then
                                s5factor <= conv_std_logic_vector(24-i,8);
                                s5factor <= conv_std_logic_vector(24-i,8);
                                s5factorhot25(24-i) <= '1';
                                s5factorhot25(24-i) <= '1';
                                exit;
                                exit;
                        end if;
                        end if;
                end loop;
                end loop;
                s5factorhot9 <= (s5factorhot25(8 downto 1)or s5factorhot25(16 downto 9)or s5factorhot25(24 downto 17)) & s5factorhot25(0);
                s5factorhot9 <= (s5factorhot25(8 downto 1)or s5factorhot25(16 downto 9)or s5factorhot25(24 downto 17)) & s5factorhot25(0);
        end process;
        end process;
 
 
 
        --! Etapa 6: Ejecutar el corrimiento para normalizar la mantissa.
        normhighshiftermult:lpm_mult
        normhighshiftermult:lpm_mult
        generic map ("DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9","UNSIGNED","LPM_MULT",9,18,27)
        generic map ("DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9","UNSIGNED","LPM_MULT",9,18,27)
        port    map (s5factorhot9,s5result(24 downto 7),s5ph);
        port    map (s6factorhot9,s6result(24 downto 7),s6ph);
        normlowshiftermult:lpm_mult
        normlowshiftermult:lpm_mult
        generic map ("DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9","UNSIGNED","LPM_MULT",9,9,18)
        generic map ("DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9","UNSIGNED","LPM_MULT",9,9,18)
        port    map (s5factorhot9,s5result(06 downto 0)&"00",s5pl);
        port    map (s6factorhot9,s6result(06 downto 0)&"00",s6pl);
        s5postshift(22 downto 15) <= s5ph(16 downto 09);
        s6postshift(22 downto 15) <= s6ph(16 downto 09);
        s5postshift(14 downto 06) <= s5ph(08 downto 00); --! Activar este pedazo si se requiere extrema precision            or s5pl(17 downto 9);
        s6postshift(14 downto 06) <= s6ph(08 downto 00); --! Activar este pedazo si se requiere extrema precision            or s5pl(17 downto 9);
        s5postshift(05 downto 00) <= s5pl(08 downto 03);
        s6postshift(05 downto 00) <= s6pl(08 downto 03);
 
 
 
 
 
 
 
 
 
 
end ema32x2_arch;
end fadd32_arch;
 
 
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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