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

Subversion Repositories raytrac

[/] [raytrac/] [trunk/] [uf.vhd] - Blame information for rev 25

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

Line No. Rev Author Line
1 22 jguarin200
--! @file raytrac.vhd
2
--! @brief Descripción del sistema aritmetico usado por raytrac.
3
--! @author Julián Andrés Guarín Reyes.
4 8 jguarin200
-- RAYTRAC
5
-- Author Julian Andres Guarin
6
-- uf.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/>.
21
 
22 22 jguarin200
--! Libreria de definicion de senales y tipos estandares, comportamiento de operadores aritmeticos y logicos.\n Signal and types definition library. This library also defines 
23 2 jguarin200
library ieee;
24 22 jguarin200
--! Paquete de definicion estandard de logica. Standard logic definition pack.
25 2 jguarin200
use ieee.std_logic_1164.all;
26 22 jguarin200
--! Se usaran en esta descripcion los componentes del package arithpack.vhd.\n It will be used in this description the components on the arithpack.vhd package. 
27 2 jguarin200
use work.arithpack.all;
28
 
29 22 jguarin200
 
30
--! uf es la descripción del circuito que realiza la aritmética del Rt Engine.
31
 
32
--! La entrada opcode indica la operación que se está realizando, en los sumadores, es la misma señal que se encuentra en la entidad opcoder, que selecciona si se está realizando un producto punto o un producto cruz. Dentro de la arquitectura de uf, la señal opcode selecciona en la primera etapa de sumadores, si la operación a realizar será una resta o una suma. 
33
--! Los resultados estarán en distintas salidas dependiendo de la operación, lo cual es apenas natural: El producto cruz tiene por resultado un vector, mientras que el producto punto tiene por resultado un escalar. 
34
--! Esta entidad utiliza las señales de control clk y rst.}
35
--! \n\n
36
--! La característica fundamental de uf, es que puede realizar 2 operaciones de producto punto al mimso tiempo ó una operación de producto cruz al mismo tiempo. La otra característica importante es que el pipe de producto punto es mas largo que el pipe de producto cruz: el producto punto tomará 3 clocks para realizarse, mientras que el procto punto tomara 4 clocks para realizarse.    
37
 
38 2 jguarin200
entity uf is
39
        port (
40 22 jguarin200
                opcode          : in std_logic; --! Entrada que dentro de la arquitectura funciona como selector de la operación que se lleva a cabo en la primera etapa de sumadores/restadores. 
41
                m0f0,m0f1,m1f0,m1f1,m2f0,m2f1,m3f0,m3f1,m4f0,m4f1,m5f0,m5f1 : in std_logic_vector(17 downto 0); --! Entradas que van conectadas a los multiplicadores en la primera etapa de la descripción.  
42
                cpx,cpy,cpz,dp0,dp1 : out std_logic_vector(31 downto 0); --! Salidas donde se registran los resultados de las operaciones aritméticas: cpx,cpy,cpz serán los componentes del vector que da por resultado el producto cruz entre los vectores AxB ó CxD.  
43
                clk,rst         : in std_logic --! Las entradas de control usuales.  
44 2 jguarin200
        );
45
end uf;
46
 
47
architecture uf_arch of uf is
48
 
49 8 jguarin200
        -- Stage 0 signals
50 2 jguarin200
 
51 22 jguarin200
        signal stage0mf00,stage0mf01,stage0mf10,stage0mf11,stage0mf20,stage0mf21,stage0mf30,stage0mf31,stage0mf40,stage0mf41,stage0mf50,stage0mf51 : std_logic_vector(17 downto 0); --! Señales que conectan los operandos seleccionados en opcode a las entradas de los multiplicadores.
52
        signal stage0p0,stage0p1, stage0p2, stage0p3, stage0p4, stage0p5 : std_logic_vector(31 downto 0); --! Señales / buses, con los productos de los multiplicadores. 
53
        signal stage0opcode : std_logic; --! Señal de atraso del opcode. Revisar el diagrama de bloques para mayor claridad.
54 2 jguarin200
 
55 8 jguarin200
        --Stage 1 signals 
56 2 jguarin200
 
57 22 jguarin200
        signal stage1p0, stage1p1, stage1p2, stage1p3, stage1p4, stage1p5 : std_logic_vector (31 downto 0); --! Señales provenientes de los productos de la etapa previa de multiplicadores.
58
        signal stage1a0, stage1a1, stage1a2 : std_logic_vector (31 downto 0); --! Señales / buses, con los resultados de los sumadores. 
59
        signal stage1opcode : std_logic; --! Señal proveniente del opcode que selecciona si los sumadores deben ejecutar una resta o una suma dependiendo de la operación que se ejecute en ese momento del pipe.  
60 2 jguarin200
 
61 8 jguarin200
        -- Some support signals
62 22 jguarin200
        signal stage1_internalCarry     : std_logic_vector(2 downto 0); --! Cada uno de los 3 sumadores de la etapa de sumadores está compuesto de una cascada de 2 sumadores Carry Look Ahead: aXhigh y aXlow. El carry out del componente low y el carry in del componente high, se conectará a través de las señales internal carry.   
63
        signal stage2_internalCarry : std_logic_vector(1 downto 0); --! Cada uno de los 2 sumadores de la última etapa de sumadores está compuesto de una cascada de 2 sumadores Carry Look AheadÑ: aXhigh y aXlow. El carry out del componente low y el carry in del componente high, se conectará a través de las señales internal carry.  
64 2 jguarin200
 
65 22 jguarin200
        --Stage 2 signals       
66
        signal stage2a0, stage2a2, stage2a3, stage2a4, stage2p2, stage2p3 : std_logic_vector (31 downto 0); --! Estas señales corresponden a los sumandos derivados de la primera etapa de multiplicadores (stage2p2, stage2p3) y a los sumandos derivados del resultado de las sumas en la primera etapa de sumadores. 
67 8 jguarin200
 
68
 
69
 
70 2 jguarin200
begin
71
 
72 8 jguarin200
        -- Multiplicator Instantiation (StAgE 0)
73 22 jguarin200
        --! Multiplicador 0 
74 14 jguarin200
        m0 : r_a18_b18_smul_c32_r
75 8 jguarin200
        port map (
76
                aclr    => rst,
77
                clock   => clk,
78 15 jguarin200
                dataa   => stage0mf00,
79
                datab   => stage0mf01,
80
                result  => stage0p0
81 8 jguarin200
        );
82 22 jguarin200
 
83
        --! Multiplicador 1
84 14 jguarin200
        m1 : r_a18_b18_smul_c32_r
85 8 jguarin200
        port map (
86
                aclr    => rst,
87
                clock   => clk,
88 15 jguarin200
                dataa   => stage0mf10,
89
                datab   => stage0mf11,
90
                result  => stage0p1
91 8 jguarin200
        );
92 22 jguarin200
 
93
        --! Multiplicador 2
94 14 jguarin200
        m2 : r_a18_b18_smul_c32_r
95 8 jguarin200
        port map (
96
                aclr    => rst,
97
                clock   => clk,
98 15 jguarin200
                dataa   => stage0mf20,
99
                datab   => stage0mf21,
100
                result  => stage0p2
101 8 jguarin200
        );
102 22 jguarin200
 
103
        --! Multiplicador 3
104 14 jguarin200
        m3 : r_a18_b18_smul_c32_r
105 8 jguarin200
        port map (
106
                aclr    => rst,
107
                clock   => clk,
108 15 jguarin200
                dataa   => stage0mf30,
109
                datab   => stage0mf31,
110
                result  => stage0p3
111 8 jguarin200
        );
112 22 jguarin200
 
113
        --! Multiplicador 4
114 14 jguarin200
        m4 : r_a18_b18_smul_c32_r
115 8 jguarin200
        port map (
116
                aclr    => rst,
117
                clock   => clk,
118 15 jguarin200
                dataa   => stage0mf40,
119
                datab   => stage0mf41,
120
                result  => stage0p4
121 8 jguarin200
        );
122 22 jguarin200
 
123
        --! Multiplicador 5
124 14 jguarin200
        m5 : r_a18_b18_smul_c32_r
125 8 jguarin200
        port map (
126
                aclr    => rst,
127
                clock   => clk,
128 15 jguarin200
                dataa   => stage0mf50,
129
                datab   => stage0mf51,
130
                result  => stage0p5
131 8 jguarin200
        );
132
 
133
        -- Adder Instantiation (sTaGe 1)
134
 
135 22 jguarin200
        --! Adder 0, 16 bit carry lookahead low adder. 
136 8 jguarin200
        a0low : adder
137
        generic map (
138 22 jguarin200
                16,"CLA","YES"  -- Carry Look Ahead Logic (More Gates Used, But Less Time)
139
                                                -- Yes instantiate Xor gates stage in the adder so we can substract on the opcode signal command.
140 8 jguarin200
        )
141
        port map        (
142 15 jguarin200
                a => stage1p0(15 downto 0),
143
                b => stage1p1(15 downto 0),
144
                s => stage1opcode,
145 8 jguarin200
                ci => '0',
146 15 jguarin200
                result => stage1a0(15 downto 0),
147
                cout => stage1_internalCarry(0)
148 8 jguarin200
        );
149 22 jguarin200
        --Adder 0, 16 bit carry lookahead high adder.
150 8 jguarin200
        a0high : adder
151
        generic map (
152
                w => 16,
153 22 jguarin200
                carry_logic             => "CLA",       -- Carry Look Ahead Logic (More Gates Used, But Less Time)
154
                substractor_selector    => "YES"        -- Yes instantiate Xor gates stage in the adder so we can substract on the opcode signal command.
155 8 jguarin200
        )
156
        port map        (
157 15 jguarin200
                a => stage1p0(31 downto 16),
158
                b => stage1p1(31 downto 16),
159
                s => stage1opcode,
160
                ci => stage1_internalCarry(0),
161
                result => stage1a0(31 downto 16),
162 8 jguarin200
                cout => open
163
        );
164 22 jguarin200
        --! Adder 1, 16 bit carry lookahead low adder. 
165 8 jguarin200
        a1low : adder
166
        generic map (
167
                w => 16,
168 22 jguarin200
                carry_logic             => "CLA",       -- Carry Look Ahead Logic (More Gates Used, But Less Time)
169
                substractor_selector    => "YES"        -- Yes instantiate Xor gates stage in the adder so we can substract on the opcode signal command.
170 8 jguarin200
        )
171
        port map        (
172 15 jguarin200
                a => stage1p2(15 downto 0),
173
                b => stage1p3(15 downto 0),
174
                s => stage1opcode,
175 8 jguarin200
                ci => '0',
176 15 jguarin200
                result => stage1a1(15 downto 0),
177
                cout => stage1_internalCarry(1)
178 8 jguarin200
        );
179 22 jguarin200
        --! Adder 1, 16 bit carry lookahead high adder.
180 8 jguarin200
        a1high : adder
181
        generic map (
182
                w => 16,
183 22 jguarin200
                carry_logic             => "CLA",       -- Carry Look Ahead Logic (More Gates Used, But Less Time)
184
                substractor_selector    => "YES"        -- Yes instantiate Xor gates stage in the adder so we can substract on the opcode signal command.
185 8 jguarin200
        )
186
        port map        (
187 15 jguarin200
                a => stage1p2(31 downto 16),
188
                b => stage1p3(31 downto 16),
189
                s => stage1opcode,
190
                ci => stage1_internalCarry(1),
191
                result => stage1a1(31 downto 16),
192 8 jguarin200
                cout => open
193
        );
194 22 jguarin200
        --! Adder 2, 16 bit carry lookahead low adder. 
195 14 jguarin200
        a2low : adder
196 8 jguarin200
        generic map (
197
                w => 16,
198 22 jguarin200
                carry_logic             => "CLA",       -- Carry Look Ahead Logic (More Gates Used, But Less Time)
199
                substractor_selector    => "YES"        -- Yes instantiate Xor gates stage in the adder so we can substract on the opcode signal command.
200 8 jguarin200
        )
201
        port map        (
202 15 jguarin200
                a => stage1p4(15 downto 0),
203
                b => stage1p5(15 downto 0),
204
                s => stage1opcode,
205 8 jguarin200
                ci => '0',
206 15 jguarin200
                result => stage1a2(15 downto 0),
207
                cout => stage1_internalCarry(2)
208 8 jguarin200
        );
209 22 jguarin200
        --! Adder 2, 16 bit carry lookahead high adder.
210 14 jguarin200
        a2high : adder
211 8 jguarin200
        generic map (
212
                w => 16,
213 22 jguarin200
                carry_logic             => "CLA",       -- Carry Look Ahead Logic (More Gates Used, But Less Time)
214
                substractor_selector    => "YES"        -- Yes instantiate Xor gates stage in the adder so we can substract on the opcode signal command.
215 8 jguarin200
        )
216
        port map        (
217 15 jguarin200
                a => stage1p4(31 downto 16),
218
                b => stage1p5(31 downto 16),
219
                s => stage1opcode,
220
                ci => stage1_internalCarry(2),
221
                result => stage1a2(31 downto 16),
222 8 jguarin200
                cout => open
223
        );
224
 
225
 
226
        -- Adder Instantiation (Stage 2)
227 22 jguarin200
        --! Adder 3, 16 bit carry lookahead low adder. 
228 8 jguarin200
        a3low : adder
229
        generic map (
230
                w => 16,
231 22 jguarin200
                carry_logic             => "CLA",       -- Carry Look Ahead Logic (More Gates Used, But Less Time)
232
                substractor_selector    => "NO"         -- No Just Add.
233 8 jguarin200
        )
234
        port map        (
235 15 jguarin200
                a => stage2a0(15 downto 0),
236
                b => stage2p2(15 downto 0),
237 14 jguarin200
                s => '0',
238 8 jguarin200
                ci => '0',
239 15 jguarin200
                result => stage2a3(15 downto 0),
240
                cout => stage2_internalCarry(0)
241 8 jguarin200
        );
242 22 jguarin200
        --Adder 3, 16 bit carry lookahead high adder.
243 8 jguarin200
        a3high : adder
244
        generic map (
245
                w => 16,
246 22 jguarin200
                carry_logic             => "CLA",       -- Carry Look Ahead Logic (More Gates Used, But Less Time)
247
                substractor_selector    => "NO"         -- No Just Add.
248 8 jguarin200
        )
249
        port map        (
250 15 jguarin200
                a => stage2a0(31 downto 16),
251
                b => stage2p2(31 downto 16),
252 14 jguarin200
                s => '0',
253 15 jguarin200
                ci => stage2_internalCarry(0),
254
                result => stage2a3(31 downto 16),
255 8 jguarin200
                cout => open
256
        );
257 22 jguarin200
        --! Adder 4, 16 bit carry lookahead low adder. 
258 8 jguarin200
        a4low : adder
259
        generic map (
260
                w => 16,
261 22 jguarin200
                carry_logic             => "CLA",       -- Carry Look Ahead Logic (More Gates Used, But Less Time)
262
                substractor_selector    => "NO"         -- No Just Add.
263 8 jguarin200
        )
264
        port map        (
265 15 jguarin200
                a => stage2p3(15 downto 0),
266
                b => stage2a2(15 downto 0),
267 14 jguarin200
                s => '0',
268 8 jguarin200
                ci => '0',
269 15 jguarin200
                result => stage2a4(15 downto 0),
270
                cout => stage2_internalCarry(1)
271 8 jguarin200
        );
272 22 jguarin200
        --! Adder 4, 16 bit carry lookahead high adder.
273 8 jguarin200
        a4high : adder
274
        generic map (
275
                w => 16,
276 22 jguarin200
                carry_logic             => "CLA",       -- Carry Look Ahead Logic (More Gates Used, But Less Time)
277
                substractor_selector    => "NO"         -- No Just Add.
278 8 jguarin200
        )
279
        port map        (
280 15 jguarin200
                a => stage2p3(31 downto 16),
281
                b => stage2a2(31 downto 16),
282 14 jguarin200
                s => '0',
283 15 jguarin200
                ci => stage2_internalCarry(1),
284
                result => stage2a4(31 downto 16),
285 8 jguarin200
                cout => open
286
        );
287
 
288
        -- Incoming from opcoder.vhd signals into pipeline's stage 0.
289 15 jguarin200
        stage0mf00 <= m0f0;
290
        stage0mf01 <= m0f1;
291
        stage0mf10 <= m1f0;
292
        stage0mf11 <= m1f1;
293
        stage0mf20 <= m2f0;
294
        stage0mf21 <= m2f1;
295
        stage0mf30 <= m3f0;
296
        stage0mf31 <= m3f1;
297
        stage0mf40 <= m4f0;
298
        stage0mf41 <= m4f1;
299
        stage0mf50 <= m5f0;
300
        stage0mf51 <= m5f1;
301 8 jguarin200
 
302
        -- Signal sequencing: as the multipliers use registered output and registered input is not necessary to write the sequence of stage 0 signals to stage 1 signals.
303
        -- so the simplistic path is taken: simply connect stage 0 to stage 1 lines. However this would not apply for the opcode signal
304 15 jguarin200
        stage1p0 <= stage0p0;
305
        stage1p1 <= stage0p1;
306
        stage1p2 <= stage0p2;
307
        stage1p3 <= stage0p3;
308
        stage1p4 <= stage0p4;
309
        stage1p5 <= stage0p5;
310 8 jguarin200
 
311
 
312
        --Outcoming to the rest of the system (by the time i wrote this i dont know where this leads to... jeje)
313 15 jguarin200
        cpx <= stage1a0;
314
        cpy <= stage1a1;
315
        cpz <= stage1a2;
316
        dp0 <= stage2a3;
317
        dp1 <= stage2a4;
318 8 jguarin200
 
319
        -- Looking into the design the stage 1 to stage 2 are the sequences pipe stages that must be controlled in this particular HDL.
320 22 jguarin200
        --! Este proceso describe la manera en que se organizan las etapas de pipe.
321
        --! Todas las señales internas en las etapas de pipe, en el momento en que la entrada rst alcanza el nivel rstMasterValue, se colocan en '0'. Nótese que, salvo stage0opcode<=stage1opcode, las señales que vienen desde la entrada hacia los multiplicadores en la etapa 0 y desde la salida de los multiplicadores desde la etapa0 hacia la etapa 1, no están siendo descritas en este proceso, la explicación de es simple: Los multiplicadores que se están instanciado tienen registros a la entrada y la salida, permitiendo así, registrar las entradas y registrar los productos o salidas de los  multiplicadores, hacia la etapa 1 o etapa de sumadores/restadores. 
322
 
323
        uf_seq: process (clk,rst)
324 8 jguarin200
        begin
325
 
326
                if rst=rstMasterValue then
327 15 jguarin200
                        stage0opcode    <= '0';
328
                        stage1opcode    <= '0';
329 3 jguarin200
 
330 15 jguarin200
                        stage2a2 <= (others => '0');
331
                        stage2p3 <= (others => '0');
332
                        stage2p2 <= (others => '0');
333
                        stage2a0 <= (others => '0');
334 8 jguarin200
 
335
                elsif clk'event and clk = '1' then
336
 
337 15 jguarin200
                        stage2a2 <= stage1a2;
338
                        stage2p3 <= stage1p3;
339
                        stage2p2 <= stage1p2;
340
                        stage2a0 <= stage1a0;
341 3 jguarin200
 
342 8 jguarin200
                        -- Opcode control sequence
343 15 jguarin200
                        stage0opcode <= opcode;
344
                        stage1opcode <= stage0opcode;
345 8 jguarin200
 
346
                end if;
347
        end process uf_seq;
348 15 jguarin200
 
349
 
350
 
351 2 jguarin200
end uf_arch;

powered by: WebSVN 2.1.0

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