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

Subversion Repositories raytrac

[/] [raytrac/] [trunk/] [arithpack.vhd] - Diff between revs 52 and 59

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

Rev 52 Rev 59
--! @file arithpack.vhd
--! @file arithpack.vhd
--! @author Julian Andres Guarin Reyes
--! @author Julian Andres Guarin Reyes
--! @brief Este package contiene la descripcion de los parametros y los puertos de las entidades: uf, opcoder, multiplicador, sumador, cla_logic_block y rca_logic_block.
--! @brief Este package contiene la descripcion de los parametros y los puertos de las entidades: uf, opcoder, multiplicador, sumador, cla_logic_block y rca_logic_block.
-- RAYTRAC
-- RAYTRAC
-- Author Julian Andres Guarin
-- Author Julian Andres Guarin
-- arithpack.vhd
-- arithpack.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/>.library ieee;
--     along with raytrac.  If not, see <http://www.gnu.org/licenses/>.library ieee;
 
 
 
 
--! Biblioteca de definicion de senales y tipos estandares, comportamiento de operadores aritmeticos y logicos. 
--! Biblioteca de definicion de senales y tipos estandares, comportamiento de operadores aritmeticos y logicos. 
library ieee;
library ieee;
--! Paquete de definicion estandard de logica.
--! Paquete de definicion estandard de logica.
use ieee.std_logic_1164.all;
use ieee.std_logic_1164.all;
 
 
--use ieee.std_logic_unsigned.conv_integer;
--use ieee.std_logic_unsigned.conv_integer;
 
 
 
 
--! Biblioteca de definicion de memorias de altera
--! Biblioteca de definicion de memorias de altera
library altera_mf;
library altera_mf;
 
 
--! Paquete para manejar memorias internas tipo M9K
--! Paquete para manejar memorias internas tipo M9K
use altera_mf.all;
use altera_mf.all;
 
 
--! Biblioteca de modulos parametrizados.
--! Biblioteca de modulos parametrizados.
library lpm;
library lpm;
use lpm.all;
use lpm.all;
 
 
--! Package de entrada y salida de texto.
--! Package de entrada y salida de texto.
use std.textio.all;
use std.textio.all;
 
 
 
 
 
 
--! Package con las definiciones de constantes y entidades, que conformaran el Rt Engine. Tambien con algunas descripciones para realizar test bench.
--! Package con las definiciones de constantes y entidades, que conformaran el Rt Engine. Tambien con algunas descripciones para realizar test bench.
 
 
--! En general el package cuenta con entidades para instanciar, multiplicadores, sumadores/restadores y un decodificador de operaciones. 
--! En general el package cuenta con entidades para instanciar, multiplicadores, sumadores/restadores y un decodificador de operaciones. 
package arithpack is
package arithpack is
 
 
        --! TestBenchState
        --! TestBenchState
        type tbState is (abcd,axb,cxd,stop);
        type tbState is (abcd,axb,cxd,stop);
 
 
        --! Constante con el nivel l&oacute;gico de reset.
        --! Constante con el nivel l&oacute;gico de reset.
        constant rstMasterValue : std_logic := '1';
        constant rstMasterValue : std_logic := '1';
 
 
        --! Constante: periodo del reloj, para una frecuencia de 50 MHz 
        --! Constante: periodo del reloj, para una frecuencia de 50 MHz 
        constant tclk : time := 20 ns;
        constant tclk : time := 20 ns;
 
 
        --! Constante: medio periodo de reloj.
        --! Constante: medio periodo de reloj.
        constant tclk2: time := tclk/2;
        constant tclk2: time := tclk/2;
 
 
        --! Constante: cuarto de periodo del reloj.
        --! Constante: cuarto de periodo del reloj.
        constant tclk4: time := tclk/4;
        constant tclk4: time := tclk/4;
 
 
 
 
        --! Generacion de Clock y de Reset.
        --! Generacion de Clock y de Reset.
        component clock_gen
        component clock_gen
                generic (tclk : time := tclk);
                generic (tclk : time := tclk);
                port    (clk,rst : out std_logic);
                port    (clk,rst : out std_logic);
        end component;
        end component;
 
 
        --! Ray Trac: Implementacion del Rt Engine
        --! Ray Trac: Implementacion del Rt Engine
        component raytrac
        component raytrac
        generic (
        generic (
                testbench_generation : string := "NO";
                testbench_generation : string := "NO";
                registered : string := "NO" --! Este parametro, por defecto "YES", indica si se registran o cargan en registros los vectores A,B,C,D y los codigos de operacion opcode y addcode en vez de ser conectados directamente al circuito combinatorio. \n This parameter, by default "YES", indicates if vectors A,B,C,D and operation code inputs opcode are to be loaded into a register at the beginning of the pipe rather than just connecting them to the operations decoder (opcoder). 
                registered : string := "NO" --! Este parametro, por defecto "YES", indica si se registran o cargan en registros los vectores A,B,C,D y los codigos de operacion opcode y addcode en vez de ser conectados directamente al circuito combinatorio. \n This parameter, by default "YES", indicates if vectors A,B,C,D and operation code inputs opcode are to be loaded into a register at the beginning of the pipe rather than just connecting them to the operations decoder (opcoder). 
        );
        );
        port (
        port (
                A,B,C,D                 : in std_logic_vector(18*3-1 downto 0); --! Vectores de entrada A,B,C,D, cada uno de tamano fijo: 3 componentes x 18 bits. \n Input vectors A,B,C,D, each one of fixed size: 3 components x 18 bits. 
                A,B,C,D                 : in std_logic_vector(18*3-1 downto 0); --! Vectores de entrada A,B,C,D, cada uno de tamano fijo: 3 componentes x 18 bits. \n Input vectors A,B,C,D, each one of fixed size: 3 components x 18 bits. 
                opcode,addcode  : in std_logic;                                                 --! Opcode and addcode input bits, opcode selects what operation is going to perform one of the entities included in the design and addcode what operands are going to be involved in such. \n Opcode & addcode, opcode selecciona que operacion se va a llevar a cabo dentro de una de las entidades referenciadas dentro de la descripcion, mientras que addcode decide cuales van a ser los operandos que realizaran tal. 
                opcode,addcode  : in std_logic;                                                 --! Opcode and addcode input bits, opcode selects what operation is going to perform one of the entities included in the design and addcode what operands are going to be involved in such. \n Opcode & addcode, opcode selecciona que operacion se va a llevar a cabo dentro de una de las entidades referenciadas dentro de la descripcion, mientras que addcode decide cuales van a ser los operandos que realizaran tal. 
                clk,rst,ena                     : in std_logic;                                                 --! Las senales de control usual. The usual control signals.
                clk,rst,ena                     : in std_logic;                                                 --! Las senales de control usual. The usual control signals.
                CPX,CPY,CPZ,DP0,DP1 : out std_logic_vector(31 downto 0)  --! Salidas que representan los resultados del RayTrac: pueden ser dos resultados, de dos operaciones de producto punto, o un producto cruz. Por favor revisar el documento de especificacion del dispositivo para tener mas claridad.\n  Outputs representing the result of the RayTrac entity: can be the results of two parallel dot product operations or the result of a single cross product, in order to clarify refere to the entity specification documentation.
                CPX,CPY,CPZ,DP0,DP1 : out std_logic_vector(31 downto 0)  --! Salidas que representan los resultados del RayTrac: pueden ser dos resultados, de dos operaciones de producto punto, o un producto cruz. Por favor revisar el documento de especificacion del dispositivo para tener mas claridad.\n  Outputs representing the result of the RayTrac entity: can be the results of two parallel dot product operations or the result of a single cross product, in order to clarify refere to the entity specification documentation.
 
 
 
 
        );
        );
        end component;
        end component;
 
 
        --! componente memoria instanciado mediante la biblioteca de altera
        --! componente memoria instanciado mediante la biblioteca de altera
        component altsyncram
        component altsyncram
        generic (
        generic (
                address_aclr_a          : string;
                address_aclr_a          : string;
                clock_enable_input_a            : string;
                clock_enable_input_a            : string;
                clock_enable_output_a           : string;
                clock_enable_output_a           : string;
                init_file               : string;
                init_file               : string;
                intended_device_family          : string;
                intended_device_family          : string;
                lpm_hint                : string;
                lpm_hint                : string;
                lpm_type                : string;
                lpm_type                : string;
                numwords_a              : natural;
                numwords_a              : natural;
                operation_mode          : string;
                operation_mode          : string;
                outdata_aclr_a          : string;
                outdata_aclr_a          : string;
                outdata_reg_a           : string;
                outdata_reg_a           : string;
                ram_block_type          : string;
                ram_block_type          : string;
                widthad_a               : natural;
                widthad_a               : natural;
                width_a         : natural;
                width_a         : natural;
                width_byteena_a         : natural
                width_byteena_a         : natural
        );
        );
        port (
        port (
                        clock0  : in std_logic ;
                        clock0  : in std_logic ;
                        address_a       : in std_logic_vector (8 downto 0);
                        address_a       : in std_logic_vector (8 downto 0);
                        q_a     : out std_logic_vector (17 downto 0)
                        q_a     : out std_logic_vector (17 downto 0)
        );
        );
        end component;  --! Entidad uf: sus siglas significan undidad funcional. La unidad funcional se encarga de realizar las diferentes operaciones vectoriales (producto cruz &oacute; producto punto). 
        end component;  --! Entidad uf: sus siglas significan undidad funcional. La unidad funcional se encarga de realizar las diferentes operaciones vectoriales (producto cruz &oacute; producto punto). 
 
 
        component uf
        component uf
        generic (
        generic (
                        use_std_logic_signed    : string := "NO";
                        use_std_logic_signed    : string := "NO";
                        testbench_generation    : string := "NO";
                        testbench_generation    : string := "NO";
                        carry_logic     : string := "CLA"
                        carry_logic     : string := "CLA"
        );
        );
        port (
        port (
                opcode          : in std_logic;
                opcode          : in std_logic;
                m0f0,m0f1,m1f0,m1f1,m2f0,m2f1,m3f0,m3f1,m4f0,m4f1,m5f0,m5f1 : in std_logic_vector(17 downto 0);
                m0f0,m0f1,m1f0,m1f1,m2f0,m2f1,m3f0,m3f1,m4f0,m4f1,m5f0,m5f1 : in std_logic_vector(17 downto 0);
                cpx,cpy,cpz,dp0,dp1 : out std_logic_vector(31 downto 0);
                cpx,cpy,cpz,dp0,dp1 : out std_logic_vector(31 downto 0);
                        clk,rst         : in std_logic
                        clk,rst         : in std_logic
        );
        );
        end component;
        end component;
 
 
        --! Entidad opcoder: opcoder decodifica la operaci&oacute;n que se va a realizar. Para tal fin coloca en la entrada de uf (unidad funcional), cuales van a ser los operandos de los multiplicadores con los que uf cuenta y adem‡s escribe en el selector de operaci&oacute;n de uf, el tipo de operaci&oacute;n a realizar.
        --! Entidad opcoder: opcoder decodifica la operaci&oacute;n que se va a realizar. Para tal fin coloca en la entrada de uf (unidad funcional), cuales van a ser los operandos de los multiplicadores con los que uf cuenta y adem‡s escribe en el selector de operaci&oacute;n de uf, el tipo de operaci&oacute;n a realizar.
        component opcoder
        component opcoder
        generic (
        generic (
                width : integer := 18;
                width : integer := 18;
                structuralDescription : string:= "NO"
                structuralDescription : string:= "NO"
        );
        );
        port (
        port (
                Ax,Bx,Cx,Dx,Ay,By,Cy,Dy,Az,Bz,Cz,Dz : in std_logic_vector (17 downto 0);
                Ax,Bx,Cx,Dx,Ay,By,Cy,Dy,Az,Bz,Cz,Dz : in std_logic_vector (17 downto 0);
                m0f0,m0f1,m1f0,m1f1,m2f0,m2f1,m3f0,m3f1,m4f0,m4f1,m5f0,m5f1 : out std_logic_vector (17 downto 0);
                m0f0,m0f1,m1f0,m1f1,m2f0,m2f1,m3f0,m3f1,m4f0,m4f1,m5f0,m5f1 : out std_logic_vector (17 downto 0);
                opcode,addcode : in std_logic
                opcode,addcode : in std_logic
        );
        );
        end component;
        end component;
 
 
        --! Multiplexor estructural.
        --! Multiplexor estructural.
        component fastmux is
        component fastmux is
        generic (
        generic (
                width : integer := 18
                width : integer := 18
        );
        );
        port (
        port (
                a,b:in std_logic_vector(width-1 downto 0);
                a,b:in std_logic_vector(width-1 downto 0);
                s:in std_logic;
                s:in std_logic;
                c: out std_logic_vector(width-1 downto 0)
                c: out std_logic_vector(width-1 downto 0)
        );
        );
        end component;
        end component;
 
 
 
 
        --! Esta entidad corresponde al multiplicador que se instanciar&iacute;a dentro de la unidad funcional. El multiplicador registra los operandos a la entrada y el respectivo producto de la multiplicaci&oacute;n a la salida. 
        --! Esta entidad corresponde al multiplicador que se instanciar&iacute;a dentro de la unidad funcional. El multiplicador registra los operandos a la entrada y el respectivo producto de la multiplicaci&oacute;n a la salida. 
        component lpm_mult
        component lpm_mult
        generic (
        generic (
                lpm_hint                : string;
                lpm_hint                : string;
                lpm_pipeline            : natural;
                lpm_pipeline            : natural;
                lpm_representation              : string;
                lpm_representation              : string;
                lpm_type                : string;
                lpm_type                : string;
                lpm_widtha              : natural;
                lpm_widtha              : natural;
                lpm_widthb              : natural;
                lpm_widthb              : natural;
                lpm_widthp              : natural
                lpm_widthp              : natural
        );
        );
        port (
        port (
                        aclr    : in std_logic ;
                aclr    : in std_logic ;
                        clock   : in std_logic ;
                clock   : in std_logic ;
                        datab   : in std_logic_vector (17 downto 0);
                datab   : in std_logic_vector (17 downto 0);
                        dataa   : in std_logic_vector (17 downto 0);
                dataa   : in std_logic_vector (17 downto 0);
                        result  : out std_logic_vector (31 downto 0)
                result  : out std_logic_vector (31 downto 0)
        );
        );
        end component;
        end component;
 
 
 
 
 
 
 
 
        --! cla_logic_block corresponde a un bloque de l&oacute;gica Carry look Ahead. Se instancia y utiliza dentro de un sumador cualquiera, pues sirve para calcular los carry out de la operaci&oacute;n. 
        --! cla_logic_block corresponde a un bloque de l&oacute;gica Carry look Ahead. Se instancia y utiliza dentro de un sumador cualquiera, pues sirve para calcular los carry out de la operaci&oacute;n. 
        component cla_logic_block
        component cla_logic_block
        generic ( width: integer:=4);
        generic ( width: integer:=4);
        port (
        port (
                p,g:in std_logic_vector(width-1 downto 0);
                p,g:in std_logic_vector(width-1 downto 0);
                cin:in std_logic;
                cin:in std_logic;
                c:out std_logic_vector(width downto 1)
                c:out std_logic_vector(width downto 1)
        );
        );
        end component;
        end component;
 
 
        --! rca_logic_block corresponde a un bloque de l&oacute;gica Ripple Carry Adder. Se instancia y utiliza dentro de un sumador cualquiera, pues sirve para calcular los carry out de la operaci&oacute;n.
        --! rca_logic_block corresponde a un bloque de l&oacute;gica Ripple Carry Adder. Se instancia y utiliza dentro de un sumador cualquiera, pues sirve para calcular los carry out de la operaci&oacute;n.
        component rca_logic_block
        component rca_logic_block
        generic ( width : integer := 4);
        generic ( width : integer := 4);
        port (
        port (
                p,g: in std_logic_vector(width-1 downto 0);
                p,g: in std_logic_vector(width-1 downto 0);
                cin: in std_logic;
                cin: in std_logic;
                c: out std_logic_vector(width downto 1)
                c: out std_logic_vector(width downto 1)
        );
        );
        end component;
        end component;
 
 
        --! Entidad sumador. Esta entidad tiene un proposito bien claro: sumar. Es altamente parametrizable. Hay 3 cosas que se pueden parametrizar: el ancho del sumador, el tipo de circuito que queremos realice la suma y si el sumador estar‡ en capacidad de realizar mediante un selector restas.
        --! Entidad sumador. Esta entidad tiene un proposito bien claro: sumar. Es altamente parametrizable. Hay 3 cosas que se pueden parametrizar: el ancho del sumador, el tipo de circuito que queremos realice la suma y si el sumador estar‡ en capacidad de realizar mediante un selector restas.
        component adder
        component adder
        generic (
        generic (
                width                                   : integer := 4;
                width                                   : integer := 4;
                carry_logic                             : string := "CLA";
                carry_logic                             : string := "CLA";
                substractor_selector    : string := "YES"
                substractor_selector    : string := "YES"
        );
        );
        port (
        port (
                a,b             :       in std_logic_vector (width-1 downto 0);
                a,b             :       in std_logic_vector (width-1 downto 0);
                s,ci    :       in      std_logic;
                s,ci    :       in      std_logic;
                result  :       out std_logic_vector (width-1 downto 0);
                result  :       out std_logic_vector (width-1 downto 0);
                cout    :       out std_logic
                cout    :       out std_logic
        );
        );
        end component;
        end component;
 
 
 
        --! Entidad raiz cuadrada para enteros de 32 bits. no worries 'jhonny g' aint no thy recepie!. 
 
        --! No es una entidad de aproximaci&acute;on, posee: etapa de decodificaci&acute e imparidad;on de direcciones,
 
        --! etapa de calculo de la raiz cuadrada mediante memoria, etapa: 
 
        component sqrt
 
 
 
        port (
 
                clk,rst :       in std_logic;   -- se&ntilde;ales de control.
 
                r               :       in std_logic_vector (31 downto 0);       --radicando
 
                s               :       out std_logic_vector (15 downto 0)
 
        );
 
        end component;
 
 
        --! Procedimiento para escribir std_logic_vectors en formato hexadecimal.
        --! Procedimiento para escribir std_logic_vectors en formato hexadecimal.
        procedure hexwrite_0(l:inout line; h: in std_logic_vector);
        procedure hexwrite_0(l:inout line; h: in std_logic_vector);
 
 
 
 
 
        component shifter is
 
        generic (
 
                address_width   : integer := 9;
 
                width                   : integer := 12
 
        );
 
        port (
 
                data                    : in std_logic_vector(width - 1 downto 0);
 
                address                 : out std_logic_vector (address_width-1 downto 0);
 
                zero                    : out std_logic;
 
                maxoneispair    : out std_logic
 
        );
 
        end component;
 
 
 
 
 
 
end package;
end package;
 
 
--! Funciones utilitarias, relacionadas sobre todo con el testbench
--! Funciones utilitarias, relacionadas sobre todo con el testbench
package body arithpack is
package body arithpack is
 
 
        constant hexchars : string (1 to 16) := "0123456789ABCDEF";
        constant hexchars : string (1 to 16) := "0123456789ABCDEF";
 
 
        procedure hexwrite_0(l:inout line;h:in std_logic_vector) is
        procedure hexwrite_0(l:inout line;h:in std_logic_vector) is
                variable index_high,index_low,highone : integer;
                variable index_high,index_low,highone : integer;
 
 
        begin
        begin
                highone := h'high-h'low;
                highone := h'high-h'low;
                for i in (highone)/4 downto 0 loop
                for i in (highone)/4 downto 0 loop
                        index_low:=i*4;
                        index_low:=i*4;
                        if (index_low+3)>highone then
                        if (index_low+3)>highone then
                                index_high := highone;
                                index_high := highone;
                        else
                        else
                                index_high := i*4+3;
                                index_high := i*4+3;
                        end if;
                        end if;
                        write(l,hexchars(1+ieee.std_logic_unsigned.conv_integer(h(index_high+h'low downto index_low+h'low))));
                        write(l,hexchars(1+ieee.std_logic_unsigned.conv_integer(h(index_high+h'low downto index_low+h'low))));
                end loop;
                end loop;
        end procedure;
        end procedure;
end package body arithpack;
end package body arithpack;
 
 

powered by: WebSVN 2.1.0

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