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

Subversion Repositories raytrac

[/] [raytrac/] [trunk/] [sqrtdiv/] [sqrtdiv.vhd] - Diff between revs 80 and 81

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 80 Rev 81
--! @file sqrtdiv.vhd
--! @file sqrtdiv.vhd
--! @brief Unidad aritm'etica para calcular la potencia de un n'umero entero elevado a la -1 (INVERSION) o a la 0.5 (SQUARE_ROOT).
--! @brief Unidad aritm'etica para calcular la potencia de un n'umero entero elevado a la -1 (INVERSION) o a la 0.5 (SQUARE_ROOT).
--! @author Juli´n Andrés Guarín Reyes.
--! @author Juli´n Andrés Guarín Reyes.
-- RAYTRAC
-- RAYTRAC
-- Author Julian Andres Guarin
-- Author Julian Andres Guarin
-- sqrtdiv.vhd
-- sqrtdiv.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
--     (at your option) any later version.
--     (at your option) any later version.
-- 
-- 
--     raytrac is distributed in the hope that it will be useful,
--     raytrac is distributed in the hope that it will be useful,
--     but WITHOUT ANY WARRANTY; without even the implied warranty of
--     but WITHOUT ANY WARRANTY; without even the implied warranty of
--     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--     GNU General Public License for more details.
--     GNU General Public License for more details.
-- 
-- 
--     You should have received a copy of the GNU General Public License
--     You should have received a copy of the GNU General Public License
--     along with raytrac.  If not, see <http://www.gnu.org/licenses/>.
--     along with raytrac.  If not, see <http://www.gnu.org/licenses/>.
 
 
 
 
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.math_real.all;
use ieee.math_real.all;
 
 
use work.arithpack.all;
use work.arithpack.all;
 
 
 
 
entity sqrtdiv is
entity sqrtdiv is
        generic (
        generic (
                reginput: string        := "YES";
                reginput: string        := "YES";
                c3width : integer       := 18;
                c3width : integer       := 18;
                functype: string        := "INVERSION";
                functype: string        := "INVERSION";
                iwidth  : integer       := 18;
                iwidth  : integer       := 32;
                owidth  : integer       := 18;
 
                awidth  : integer       := 9
                awidth  : integer       := 9
        );
        );
        port (
        port (
                clk,rst : in std_logic;
                clk,rst : in std_logic;
                value   : in std_logic_vector (iwidth-1 downto 0);
                value   : in std_logic_vector (iwidth-1 downto 0);
                zero    : out std_logic;
                zero    : out std_logic;
                result  : out std_logic_vector (owidth-1 downto 0)
 
 
                sqr             : out std_logic_vector (15 downto 0);
 
                inv             : out std_logic_vector (16 downto 0)
        );
        );
end sqrtdiv;
end sqrtdiv;
 
 
architecture sqrtdiv_arch of sqrtdiv is
architecture sqrtdiv_arch of sqrtdiv is
 
 
        --! expomantis::Primera etapa: Calculo parcial de la mantissa y el exponente.
        --! expomantis::Primera etapa: Calculo parcial de la mantissa y el exponente.
        signal expomantisvalue  : std_logic_vector (iwidth-1 downto 0);
        signal expomantisvalue  : std_logic_vector (iwidth-1 downto 0);
 
 
        signal expomantisexp    : std_logic_vector (2*integer(ceil(log(real(iwidth),2.0)))-1 downto 0);
        signal expomantisexp    : std_logic_vector (2*integer(ceil(log(real(iwidth),2.0)))-1 downto 0);
        signal expomantisadd    : std_logic_vector (2*awidth-1 downto 0);
        signal expomantisadd    : std_logic_vector (2*awidth-1 downto 0);
        signal expomantiszero   : std_logic;
        signal expomantiszero   : std_logic;
 
 
        --! funky::Segunda etapa: Calculo del valor de la funcion evaluada en f.
        --! funky::Segunda etapa: Calculo del valor de la funcion evaluada en f.
        signal funkyadd                 : std_logic_vector (2*awidth-1 downto 0);
        signal funkyadd                 : std_logic_vector (2*awidth-1 downto 0);
        signal funkyexp                 : std_logic_vector (2*integer(ceil(log(real(iwidth),2.0)))-1 downto 0);
        signal funkyexp                 : std_logic_vector (2*integer(ceil(log(real(iwidth),2.0)))-1 downto 0);
        signal funkyzero                : std_logic;
        signal funkyzero                : std_logic;
 
 
        signal funkyq                   : std_logic_vector (2*c3width+3 downto 0);
        signal funkyq                   : std_logic_vector (2*c3width-1  downto 0);
        signal funkyselector    : std_logic;
        signal funkyselector    : std_logic;
 
 
        --! cumpa::Tercera etapa: Selecci'on de valores de acuerdo al exp escogido.
        --! cumpa::Tercera etapa: Selecci'on de valores de acuerdo al exp escogido.
        signal cumpaexp                 : std_logic_vector (2*integer(ceil(log(real(iwidth),2.0)))-1 downto 0);
        signal cumpaexp                 : std_logic_vector (2*integer(ceil(log(real(iwidth),2.0)))-1 downto 0);
        signal cumpaq                   : std_logic_vector (2*c3width+3 downto 0);
        signal cumpaq                   : std_logic_vector (2*c3width-1 downto 0);
        signal cumpaselector    : std_logic;
        signal cumpaselector    : std_logic;
        signal cumpazero                : std_logic;
        signal cumpazero                : std_logic;
 
 
        signal cumpaN                   : std_logic_vector (integer(ceil(log(real(iwidth),2.0)))-1 downto 0);
        signal cumpaN                   : std_logic_vector (integer(ceil(log(real(iwidth),2.0)))-1 downto 0);
        signal cumpaF                   : std_logic_vector (c3width+1 downto 0);
        signal cumpaF                   : std_logic_vector (c3width-1 downto 0);
 
 
        --! chief::Cuarta etapa: Corrimiento a la izquierda o derecha, para el caso de la ra'iz cuadrada o la inversi'on respectivamente. 
        --! chief::Cuarta etapa: Corrimiento a la izquierda o derecha, para el caso de la ra'iz cuadrada o la inversi'on respectivamente. 
 
 
        signal chiefN                   : std_logic_vector (integer(ceil(log(real(iwidth),2.0)))-1 downto 0);
        signal chiefN                   : std_logic_vector (integer(ceil(log(real(iwidth),2.0)))-1 downto 0);
        signal chiefF                   : std_logic_vector (c3width+1 downto 0);
        signal chiefF                   : std_logic_vector (c3width-1 downto 0);
 
        signal chiefQ                   : std_logic_vector (c3width-1 downto 0);
 
 
 
        --! inverseDistance::Quinta etapa
 
 
 
        signal iDistN                   : std_logic_vector (integer(ceil(log(real(iwidth),2.0)))-1 downto 0);
 
        signal iDistF                   : std_logic_vector (c3width-1 downto 0);
        --! Constantes para manejar el tama&ntilde;o de los vectores
        --! Constantes para manejar el tama&ntilde;o de los vectores
        constant exp1H : integer := 2*integer(ceil(log(real(iwidth),2.0)))-1;
        constant exp1H : integer := 2*integer(ceil(log(real(iwidth),2.0)))-1;
        constant exp1L : integer := integer(ceil(log(real(iwidth),2.0)));
        constant exp1L : integer := integer(ceil(log(real(iwidth),2.0)));
        constant exp0H : integer := exp1L-1;
        constant exp0H : integer := exp1L-1;
        constant exp0L : integer := 0;
        constant exp0L : integer := 0;
        constant add1H : integer := 2*awidth-1;
        constant add1H : integer := 2*awidth-1;
        constant add1L : integer := awidth;
        constant add1L : integer := awidth;
        constant add0H : integer := awidth-1;
        constant add0H : integer := awidth-1;
        constant add0L : integer := 0;
        constant add0L : integer := 0;
 
 
 
 
        constant c3qHH : integer := 2*c3width+3;
        constant c3qHH : integer := 2*c3width-1;
        constant c3qHL : integer := c3width+2;
        constant c3qHL : integer := c3width;
        constant c3qLH : integer := c3width+1;
        constant c3qLH : integer := c3width-1;
        constant c3qLL : integer := 0;
        constant c3qLL : integer := 0;
 
 
begin
begin
 
 
        --! expomantis.
        --! expomantis.
        expomantisreg:
        expomantisreg:
        if reginput="YES" generate
        if reginput="YES" generate
                expomantisProc:
                expomantisProc:
                process (clk,rst)
                process (clk,rst)
                begin
                begin
                        if rst=rstMasterValue then
                        if rst=rstMasterValue then
                                expomantisvalue <= (others =>'0');
                                expomantisvalue <= (others =>'0');
                        elsif clk'event and clk='1' then
                        elsif clk'event and clk='1' then
                                expomantisvalue <= value;
                                expomantisvalue <= value;
                        end if;
                        end if;
                end process expomantisProc;
                end process expomantisProc;
        end generate expomantisreg;
        end generate expomantisreg;
 
 
        expomantisnoreg:
        expomantisnoreg:
        if reginput ="NO" generate
        if reginput ="NO" generate
                expomantisvalue<=value;
                expomantisvalue<=value;
        end generate expomantisnoreg;
        end generate expomantisnoreg;
 
 
        expomantisshifter2x:shifter2xstage
        expomantisshifter2x:shifter2xstage
        generic map(awidth,iwidth)
        generic map(awidth,iwidth)
        port map(expomantisvalue,expomantisexp,expomantisadd,expomantiszero);
        port map(expomantisvalue,expomantisexp,expomantisadd,expomantiszero);
 
 
        --! funky.
        --! funky.
        funkyProc:
        funkyProc:
        process (clk,rst,expomantisexp, expomantiszero)
        process (clk,rst,expomantisexp, expomantiszero)
        begin
        begin
                if rst=rstMasterValue then
                if rst=rstMasterValue then
                        funkyexp <= (others => '0');
                        funkyexp <= (others => '0');
                        funkyzero <= '0';
                        funkyzero <= '0';
                        funkyadd <= (others => '0');
                        funkyadd <= (others => '0');
 
 
                elsif clk'event and clk='1' then
                elsif clk'event and clk='1' then
 
 
                        funkyexp(exp1H downto 0) <= expomantisexp(exp1H downto 0);
                        funkyexp(exp1H downto 0) <= expomantisexp(exp1H downto 0);
                        funkyzero <= expomantiszero;
                        funkyzero <= expomantiszero;
                        funkyadd <= expomantisadd;
                        funkyadd <= expomantisadd;
 
 
                end if;
                end if;
        end process funkyProc;
        end process funkyProc;
 
 
        funkyget:
        funkyget:
        process (funkyexp)
        process (funkyexp)
        begin
        begin
                if (funkyexp(exp0H downto 0)>funkyexp(exp1H downto exp1L)) then
                if (funkyexp(exp0H downto 0)>funkyexp(exp1H downto exp1L)) then
                        funkyselector<='0';
                        funkyselector<='0';
                else
                else
                        funkyselector<='1';
                        funkyselector<='1';
                end if;
                end if;
        end process funkyget;
        end process funkyget;
 
 
        funkyinversion:
 
        if functype="INVERSION" generate
 
                meminvr:func
 
                generic map (memoryPath&"meminvr.mif")
 
                port map(
 
                        expomantisadd(awidth-1 downto 0),
 
                        expomantisadd(2*awidth-1 downto awidth),
 
                        clk,
 
                        funkyq(c3qLH-2 downto c3qLL),
 
                        funkyq(c3qHH-2 downto c3qHL));
 
 
 
        end generate funkyinversion;
 
        funkysquare_root:
        sqrt: funcinvr
        if functype="SQUARE_ROOT" generate
 
                sqrt: func
 
                generic map (memoryPath&"memsqrt.mif")
                generic map (memoryPath&"memsqrt.mif")
                port map(
                port map(
                        expomantisadd(awidth-1 downto 0),
                funkyadd(awidth-1 downto 0),
                        (others => '0'),
 
                        clk,
                        clk,
                        funkyq(c3qLH-2 downto c3qLL),
                funkyq(c3qLH downto c3qLL));
                        open);
 
 
 
                sqrt2x: func
        sqrt2x: funcinvr
                generic map (memoryPath&"memsqrt2f.mif")
                generic map (memoryPath&"memsqrt2f.mif")
                port map(
                port map(
                        (others => '0'),
                funkyadd(2*awidth-1 downto awidth),
                        expomantisadd(2*awidth-1 downto awidth),
 
                        clk,
                        clk,
                        open,
                funkyq(c3qHH downto c3qHL));
                        funkyq(c3qHH-2 downto c3qHL));
 
 
 
        end generate funkysquare_root;
 
 
 
        --! cumpa.
        --! cumpa.
        cumpaProc:
        cumpaProc:
        process (clk,rst)
        process (clk,rst)
        begin
        begin
                if rst=rstMasterValue then
                if rst=rstMasterValue then
                        cumpaselector <= '0';
                        cumpaselector <= '0';
                        cumpazero <= '0';
                        cumpazero <= '0';
                        cumpaexp <= (others => '0');
                        cumpaexp <= (others => '0');
                        cumpaq <= (others => '0');
                        cumpaq <= (others => '0');
                elsif clk'event and clk='1' then
                elsif clk'event and clk='1' then
                        cumpaselector <= funkyselector;
                        cumpaselector <= funkyselector;
                        cumpazero <= funkyzero;
                        cumpazero <= funkyzero;
                        cumpaexp <= funkyexp;
                        cumpaexp <= funkyexp;
                        cumpaq <= funkyq;
                        cumpaq <= funkyq;
                end if;
                end if;
        end process cumpaProc;
        end process cumpaProc;
        cumpaMux:
        cumpaMux:
        process (cumpaq,cumpaexp,cumpaselector)
        process (cumpaq,cumpaexp,cumpaselector)
        begin
        begin
                if cumpaselector='0' then
                if cumpaselector='0' then
                        cumpaN<=cumpaexp(exp0H downto exp0L);
                        cumpaN<=cumpaexp(exp0H downto exp0L);
                        cumpaF<=cumpaq(c3qLH downto c3qLL);
                        cumpaF<=cumpaq(c3qLH downto c3qLL);
                else
                else
                        cumpaN<=cumpaexp(exp1H downto exp1L);
                        cumpaN<=cumpaexp(exp1H downto exp1L);
                        cumpaF<=cumpaq(c3qHH downto c3qHL);
                        cumpaF<=cumpaq(c3qHH downto c3qHL);
                end if;
                end if;
        end process cumpaMux;
        end process cumpaMux;
 
 
        --! chief.
        --! Branching.
 
        -- exp <= chiefN;
 
        -- fadd <= chiefF(c3width-2 downto c3width-1-awidth);
        chiefProc:
        chiefProc:
        process (clk,rst)
        process (clk,rst)
        begin
        begin
                if rst=rstMasterValue then
                if rst=rstMasterValue then
                        chiefF <= (others => '0');
                        chiefF <= (others => '0');
                        chiefN <= (others => '0');
                        chiefN <= (others => '0');
                elsif clk'event and clk='1' then
                elsif clk'event and clk='1' then
                        chiefF <= cumpaF;
                        chiefF <= cumpaF;
                        chiefN <= cumpaN;
                        chiefN <= cumpaN;
                        zero <= cumpazero;
                        zero <= cumpazero;
                end if;
                end if;
        end process chiefProc;
        end process chiefProc;
        chiefShifter: RLshifter
        chiefShifter: RLshifter
        generic map(functype,c3width+2,iwidth,owidth)
        generic map("SQUARE_ROOT",c3width,iwidth,16)
        port map(
        port map(
                chiefN,
                chiefN,
                chiefF,
                chiefF,
                result);
                sqr);
 
        branching_invfunc:
 
        if functype="INVERSION" generate
 
                sqrt: funcinvr
 
                generic map (memoryPath&"meminvr.mif")
 
                port map(
 
                        chiefF(c3width-2 downto c3width-1-awidth),
 
                        clk,
 
                        chiefQ(c3width-1 downto 0));
 
 
 
 
 
 
 
        end generate branching_invfunc;
 
 
 
        branchingHighLander:
 
        if functype="SQUARE_ROOT" generate
 
                chiefQ <= (others => '0');
 
        end generate branchingHighLander;
 
 
 
        --! Inverse
 
        inverseDistanceOK:
 
        if functype="INVERSION" generate
 
 
 
                inverseDistance:
 
                process (clk,rst)
 
                begin
 
 
 
                        if rst=rstMasterValue then
 
                                iDistN <= (others => '0');
 
                                iDistF <= (others => '0');
 
                        elsif clk'event and clk='1' then
 
                                iDistN <= chiefN;
 
                                iDistF <= chiefQ;
 
                        end if;
 
 
 
 
 
                end process inverseDistance;
 
 
 
                inverseShifter: RLshifter
 
                generic map("INVERSION",c3width,iwidth,17)
 
                port map(
 
                        iDistN,
 
                        iDistF,
 
                        inv);
 
        end generate inverseDistanceOK;
 
 
 
        inverseDistanceNOTOK:
 
        if functype = "SQUARE_ROOT" generate
 
                iDistN <= (others => '0');
 
                iDistF <= (others => '0');
 
                inv <= (others => '0');
 
        end generate inverseDistanceNOTOK;
 
 
end sqrtdiv_arch;
end sqrtdiv_arch;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

powered by: WebSVN 2.1.0

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