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

Subversion Repositories raytrac

[/] [raytrac/] [trunk/] [sqrtdiv/] [sqrtdiv.vhd] - Diff between revs 73 and 74

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

Rev 73 Rev 74
Line 18... Line 18...
-- 
-- 
--     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;
 
 
Line 31... Line 31...
 
 
entity sqrtdiv is
entity sqrtdiv is
        generic (
        generic (
                reginput: string        := "YES";
                reginput: string        := "YES";
                c3width : integer       := 18;
                c3width : integer       := 18;
                functype: string        := "SQUARE_ROOT";
                functype: string        := "INVERSION";
                iwidth  : integer       := 32;
                iwidth  : integer       := 32;
                owidth  : integer       := 16;
                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);
Line 67... Line 67...
        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-1 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 (2*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 (2*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);
 
 
 
 
 
        --! Constantes para manejar el tama&ntilde;o de los vectores
 
        constant exp1H : integer := 2*integer(ceil(log(real(iwidth),2.0)))-1;
 
        constant exp1L : integer := integer(ceil(log(real(iwidth),2.0)));
 
        constant exp0H : integer := exp1L-1;
 
        constant exp0L : integer := 0;
 
        constant add1H : integer := 2*awidth-1;
 
        constant add1L : integer := awidth;
 
        constant add0H : integer := add1L-1;
 
        constant add0L : integer := 0;
 
 
 
 
 
        constant c3qHH : integer := 2*c3width-1;
 
        constant c3qHL : integer := c3width;
 
        constant c3qLH : integer := c3width-1;
 
        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 <= vale;
                                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)
        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';
                else
                elsif clk'event and clk='1' then
                        funkyexp <= expomantisexp;
                        funkyexp(exp1H downto 0) <= expomantisexp(exp1H downto 0);
                        funkyzero <= expomantiszero;
                        funkyzero <= expomantiszero;
                end if;
                end if;
        end process funkyProc;
        end process funkyProc;
        funkyadd <= expomantisadd;
        funkyadd <= expomantisadd;
        funkyget:
        funkyget:
        process (funkyexp)
        process (funkyexp)
        begin
        begin
                if (funkyexp(integer(ceil(log(real(iwidth),2.0)))-1 downto 0)>funkyexp(2*integer(ceil(log(real(iwidth),2.0)))-1 downto integer(ceil(log(real(iwidth),2.0))))) 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:
        funkyinversion:
        if functype="INVERSION" generate
        if functype="INVERSION" generate
                meminvr:func
                meminvr:func
                generic map ("X:/Tesis/Workspace/hw/rt_lib/arith/src/trunk/sqrtdiv/meminvr.mif")
                generic map ("X:/Tesis/Workspace/hw/rt_lib/arith/src/trunk/sqrtdiv/meminvr.mif")
                port map(
                port map(
                        funkyadd(integer(ceil(log(real(iwidth),2.0)))-1 downto 0),
                        funkyadd(add0H downto add0L),
                        funkyadd(2*integer(ceil(log(real(iwidth),2.0)))-1 downto integer(ceil(log(real(iwidth),2.0)))),
                        funkyadd(add1H downto add1L),
                        clk,
                        clk,
                        funkyq(c3width-1 downto 0),
                        funkyq(c3qLH downto c3qLL),
                        funkyq(2*c3width-1 downto c3width));
                        funkyq(c3qHH downto c3qHL));
        end generate funkyinversion;
        end generate funkyinversion;
        funkysquare_root:
        funkysquare_root:
        if functype="SQUARE_ROOT" generate
        if functype="SQUARE_ROOT" generate
                sqrt: func
                sqrt: func
                generic map ("X:/Tesis/Workspace/hw/rt_lib/arith/src/trunk/sqrtdiv/memsqrt.mif")
                generic map ("X:/Tesis/Workspace/hw/rt_lib/arith/src/trunk/sqrtdiv/memsqrt.mif")
                port map(
                port map(
                        funkyadd(integer(ceil(log(real(iwidth),2.0)))-1 downto 0),
                        funkyadd(add0H downto add0L),
                        ad1 => (others => '0'),
                        (others => '0'),
                        clk,
                        clk,
                        funkyq(c3width-1 downto 0),
                        funkyq(c3qLH downto c3qLL),
                        open);
                        open);
 
 
                sqrt2x: func
                sqrt2x: func
                generic map ("X:/Tesis/Workspace/hw/rt_lib/arith/src/trunk/sqrtdiv/memsqrt2f.mif")
                generic map ("X:/Tesis/Workspace/hw/rt_lib/arith/src/trunk/sqrtdiv/memsqrt2f.mif")
                port map(
                port map(
                        ad0 => (others => '0'),
                        (others => '0'),
                        funkyadd(2*integer(ceil(log(real(iwidth),2.0)))-1 downto integer(ceil(log(real(iwidth),2.0)))),
                        funkyadd(add1H downto add1L),
                        clk,
                        clk,
                        open,
                        open,
                        funkyq(2*c3width-1 downto c3width));
                        funkyq(c3qHH downto c3qHL));
        end generate funkysquare_root;
        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 <= (others => '0');
                        cumpaselector <= '0';
                        cumpazero <= (others => '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;
Line 175... Line 192...
        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(integer(ceil(log(real(iwidth),2.0)))-1 downto 0);
                        cumpaN<=cumpaexp(exp0H downto exp0L);
                        cumpaF<=cumpaq(c3width-1 downto 0);
                        cumpaF<=cumpaq(c3qLH downto c3qLL);
                else
                else
                        cumpaN<=cumpaexp(2*integer(ceil(log(real(iwidth),2.0)))-1 downto integer(ceil(log(real(iwidth),2.0))));
                        cumpaN<=cumpaexp(exp1H downto exp1L);
                        cumpaF<=cumpaq(2*c3width-1 downto c3width);
                        cumpaF<=cumpaq(c3qHH downto c3qHL);
                end if;
                end if;
        end process cumpaMux;
        end process cumpaMux;
 
 
        --! chief.
        --! chief.
        chiefProc:
        chiefProc:
Line 196... Line 213...
                        chiefF <= cumpaF;
                        chiefF <= cumpaF;
                        chiefN <= cumpaN;
                        chiefN <= cumpaN;
                        zero <= cumpazero;
                        zero <= cumpazero;
                end if;
                end if;
        end process chiefProc;
        end process chiefProc;
        cumpaShifter: RLshifter
        chiefShifter: RLshifter
        generic map(functype,c3width,owidth)
        generic map(functype,c3width,iwidth,owidth)
        port map(chiefN,chiefF,result);
        port map(
 
                chiefN,
 
                chiefF,
 
                result);
 
 
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.