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

Subversion Repositories raytrac

[/] [raytrac/] [trunk/] [arithpack.vhd] - Blame information for rev 51

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 23 jguarin200
--! @file arithpack.vhd
2 43 jguarin200
--! @author Julian Andres Guarin Reyes
3
--! @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.
4 16 jguarin200
-- RAYTRAC
5
-- Author Julian Andres Guarin
6
-- arithpack.vhd
7
-- This file is part of raytrac.
8
-- 
9
--     raytrac is free software: you can redistribute it and/or modify
10
--     it under the terms of the GNU General Public License as published by
11
--     the Free Software Foundation, either version 3 of the License, or
12
--     (at your option) any later version.
13
-- 
14
--     raytrac is distributed in the hope that it will be useful,
15
--     but WITHOUT ANY WARRANTY; without even the implied warranty of
16
--     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
--     GNU General Public License for more details.
18
-- 
19
--     You should have received a copy of the GNU General Public License
20
--     along with raytrac.  If not, see <http://www.gnu.org/licenses/>.library ieee;
21
 
22
 
23 23 jguarin200
--! Biblioteca de definicion de senales y tipos estandares, comportamiento de operadores aritmeticos y logicos. 
24 22 jguarin200
library ieee;
25 23 jguarin200
--! Paquete de definicion estandard de logica.
26 2 jguarin200
use ieee.std_logic_1164.all;
27
 
28 49 jguarin200
--use ieee.std_logic_unsigned.conv_integer;
29
 
30
 
31 43 jguarin200
--! Biblioteca de definicion de memorias de altera
32
library altera_mf;
33
--! Paquete para manejar memorias internas tipo M9K
34 47 jguarin200
use altera_mf.all;
35 8 jguarin200
 
36 47 jguarin200
--! Biblioteca de modulos parametrizados.
37
library lpm;
38
use lpm.all;
39 49 jguarin200
 
40
--! Package de entrada y salida de texto.
41
use std.textio.all;
42
 
43
 
44
 
45 43 jguarin200
--! Package con las definiciones de constantes y entidades, que conformaran el Rt Engine. Tambien con algunas descripciones para realizar test bench.
46 8 jguarin200
 
47 23 jguarin200
--! En general el package cuenta con entidades para instanciar, multiplicadores, sumadores/restadores y un decodificador de operaciones. 
48 2 jguarin200
package arithpack is
49 10 jguarin200
 
50 45 jguarin200
        --! TestBenchState
51
        type tbState is (abcd,axb,cxd,stop);
52
 
53 23 jguarin200
        --! Constante con el nivel l—gico de reset.
54 15 jguarin200
        constant rstMasterValue : std_logic := '1';
55 40 jguarin200
 
56 49 jguarin200
        --! Constante: periodo del reloj;
57
        constant tclk : time := 20 ns;
58
        constant tclk2: time := tclk/2;
59
        constant tclk4: time := tclk/4;
60
 
61
 
62 42 jguarin200
        --! Generacion de Clock y de Reset.
63
        component clock_gen
64 49 jguarin200
                generic (tclk : time := tclk);
65 42 jguarin200
                port    (clk,rst : out std_logic);
66
        end component;
67
 
68 44 jguarin200
        --! Ray Trac: Implementacion del Rt Engine
69
        component raytrac
70
        generic (
71 50 jguarin200
                testbench_generation : string := "NO";
72 44 jguarin200
                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). 
73
        );
74
        port (
75
                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. 
76
                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. 
77
                clk,rst,ena                     : in std_logic;                                                 --! Las senales de control usual. The usual control signals.
78
                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.
79
 
80
 
81
        );
82
        end component;
83 42 jguarin200
 
84 47 jguarin200
        --! componente memoria instanciado mediante la biblioteca de altera
85 43 jguarin200
        component altsyncram
86 40 jguarin200
        generic (
87 43 jguarin200
                address_aclr_a          : string;
88
                clock_enable_input_a            : string;
89
                clock_enable_output_a           : string;
90
                init_file               : string;
91
                intended_device_family          : string;
92
                lpm_hint                : string;
93
                lpm_type                : string;
94
                numwords_a              : natural;
95
                operation_mode          : string;
96
                outdata_aclr_a          : string;
97
                outdata_reg_a           : string;
98
                ram_block_type          : string;
99
                widthad_a               : natural;
100
                width_a         : natural;
101
                width_byteena_a         : natural
102 40 jguarin200
        );
103 43 jguarin200
        port (
104
                        clock0  : in std_logic ;
105
                        address_a       : in std_logic_vector (8 downto 0);
106
                        q_a     : out std_logic_vector (17 downto 0)
107
        );
108
        end component;  --! Entidad uf: sus siglas significan undidad funcional. La unidad funcional se encarga de realizar las diferentes operaciones vectoriales (producto cruz — producto punto). 
109
 
110 8 jguarin200
        component uf
111 27 jguarin200
        generic (
112 32 jguarin200
                        use_std_logic_signed    : string := "NO";
113 50 jguarin200
                        testbench_generation    : string := "NO";
114 32 jguarin200
                        carry_logic     : string := "CLA"
115 27 jguarin200
        );
116 8 jguarin200
        port (
117
                opcode          : in std_logic;
118 12 jguarin200
                m0f0,m0f1,m1f0,m1f1,m2f0,m2f1,m3f0,m3f1,m4f0,m4f1,m5f0,m5f1 : in std_logic_vector(17 downto 0);
119 13 jguarin200
                cpx,cpy,cpz,dp0,dp1 : out std_logic_vector(31 downto 0);
120 40 jguarin200
                        clk,rst         : in std_logic
121 8 jguarin200
        );
122
        end component;
123
 
124 23 jguarin200
        --! Entidad opcoder: opcoder decodifica la operaci—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—n de uf, el tipo de operaci—n a realizar.
125 8 jguarin200
        component opcoder
126 25 jguarin200
        generic (
127
                width : integer := 18;
128
                structuralDescription : string:= "NO"
129 26 jguarin200
        );
130 8 jguarin200
        port (
131
                Ax,Bx,Cx,Dx,Ay,By,Cy,Dy,Az,Bz,Cz,Dz : in std_logic_vector (17 downto 0);
132 14 jguarin200
                m0f0,m0f1,m1f0,m1f1,m2f0,m2f1,m3f0,m3f1,m4f0,m4f1,m5f0,m5f1 : out std_logic_vector (17 downto 0);
133 8 jguarin200
                opcode,addcode : in std_logic
134
        );
135
        end component;
136 24 jguarin200
 
137
        --! Multiplexor estructural.
138 26 jguarin200
        component fastmux is
139 24 jguarin200
        generic (
140
                width : integer := 18
141 26 jguarin200
        );
142 24 jguarin200
        port (
143 26 jguarin200
                a,b:in std_logic_vector(width-1 downto 0);
144 24 jguarin200
                s:in std_logic;
145 26 jguarin200
                c: out std_logic_vector(width-1 downto 0)
146
        );
147
        end component;
148 50 jguarin200
 
149
 
150 23 jguarin200
        --! Esta entidad corresponde al multiplicador que se instanciar’a dentro de la unidad funcional. El multiplicador registra los operandos a la entrada y el respectivo producto de la multiplicaci—n a la salida. 
151 50 jguarin200
        component lpm_mult
152 47 jguarin200
        generic (
153 50 jguarin200
                lpm_hint                : string;
154
                lpm_pipeline            : natural;
155
                lpm_representation              : string;
156
                lpm_type                : string;
157
                lpm_widtha              : natural;
158
                lpm_widthb              : natural;
159
                lpm_widthp              : natural
160 47 jguarin200
        );
161 2 jguarin200
        port (
162 50 jguarin200
                        aclr    : in std_logic ;
163
                        clock   : in std_logic ;
164
                        datab   : in std_logic_vector (17 downto 0);
165
                        dataa   : in std_logic_vector (17 downto 0);
166
                        result  : out std_logic_vector (31 downto 0)
167 2 jguarin200
        );
168
        end component;
169 50 jguarin200
 
170 23 jguarin200
 
171 50 jguarin200
 
172
 
173 23 jguarin200
        --! cla_logic_block corresponde a un bloque de l—gica Carry look Ahead. Se instancia y utiliza dentro de un sumador cualquiera, pues sirve para calcular los carry out de la operaci—n. 
174 2 jguarin200
        component cla_logic_block
175 27 jguarin200
        generic ( width: integer:=4);
176 2 jguarin200
        port (
177 27 jguarin200
                p,g:in std_logic_vector(width-1 downto 0);
178 2 jguarin200
                cin:in std_logic;
179 27 jguarin200
                c:out std_logic_vector(width downto 1)
180 2 jguarin200
        );
181
        end component;
182 23 jguarin200
 
183
        --! rca_logic_block corresponde a un bloque de l—gica Ripple Carry Adder. Se instancia y utiliza dentro de un sumador cualquiera, pues sirve para calcular los carry out de la operaci—n.
184 2 jguarin200
        component rca_logic_block
185 27 jguarin200
        generic ( width : integer := 4);
186 2 jguarin200
        port (
187 27 jguarin200
                p,g: in std_logic_vector(width-1 downto 0);
188 2 jguarin200
                cin: in std_logic;
189 27 jguarin200
                c: out std_logic_vector(width downto 1)
190 2 jguarin200
        );
191
        end component;
192 23 jguarin200
 
193
        --! 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.
194 2 jguarin200
        component adder
195
        generic (
196 27 jguarin200
                width                                   : integer := 4;
197 14 jguarin200
                carry_logic                             : string := "CLA";
198
                substractor_selector    : string := "YES"
199 2 jguarin200
        );
200
        port (
201 27 jguarin200
                a,b             :       in std_logic_vector (width-1 downto 0);
202 2 jguarin200
                s,ci    :       in      std_logic;
203 27 jguarin200
                result  :       out std_logic_vector (width-1 downto 0);
204 2 jguarin200
                cout    :       out std_logic
205
        );
206
        end component;
207 49 jguarin200
 
208
 
209
        procedure hexwrite_0(l:inout line; h: in std_logic_vector);
210
 
211 2 jguarin200
end package;
212 49 jguarin200
 
213
package body arithpack is
214
        --! Funciones utilitarias, relacionadas sobre todo con el testbench
215
        constant hexchars : string (1 to 16) := "0123456789ABCDEF";
216
 
217
        procedure hexwrite_0(l:inout line;h:in std_logic_vector) is
218 50 jguarin200
                variable index_high,index_low,highone : integer;
219
 
220 49 jguarin200
        begin
221 50 jguarin200
                highone := h'high-h'low;
222
                for i in (highone)/4 downto 0 loop
223 49 jguarin200
                        index_low:=i*4;
224 50 jguarin200
                        if (index_low+3)>highone then
225
                                index_high := highone;
226 49 jguarin200
                        else
227
                                index_high := i*4+3;
228
                        end if;
229 50 jguarin200
                        write(l,hexchars(1+ieee.std_logic_unsigned.conv_integer(h(index_high+h'low downto index_low+h'low))));
230 49 jguarin200
                end loop;
231
        end procedure;
232
end package body arithpack;

powered by: WebSVN 2.1.0

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