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

Subversion Repositories raytrac

[/] [raytrac/] [branches/] [fp/] [dpc.vhd] - Blame information for rev 145

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

Line No. Rev Author Line
1 123 jguarin200
--! @file dpc.vhd
2 122 jguarin200
--! @brief Decodificador de operacion. 
3 128 jguarin200
--! @author Julián Andrés Guarín Reyes
4 122 jguarin200
--------------------------------------------------------------
5
-- RAYTRAC
6
-- Author Julian Andres Guarin
7 123 jguarin200
-- dpc.vhd
8 122 jguarin200
-- This file is part of raytrac.
9
-- 
10
--     raytrac is free software: you can redistribute it and/or modify
11
--     it under the terms of the GNU General Public License as published by
12
--     the Free Software Foundation, either version 3 of the License, or
13
--     (at your option) any later version.
14
-- 
15
--     raytrac is distributed in the hope that it will be useful,
16
--     but WITHOUT ANY WARRANTY; without even the implied warranty of
17
--     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
--     GNU General Public License for more details.
19
-- 
20
--     You should have received a copy of the GNU General Public License
21
--     along with raytrac.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
library ieee;
24
use ieee.std_logic_1164.all;
25 134 jguarin200
 
26 123 jguarin200
entity dpc is
27 122 jguarin200
        generic (
28 132 jguarin200
                width : integer := 32
29
                --!external_readable_widthad    : integer := integer(ceil(log(real(external_readable_blocks),2.0))))                    
30 122 jguarin200
        );
31
        port (
32 143 jguarin200
                clk,rst                                 : in    std_logic;
33 127 jguarin200
                paraminput                              : in    std_logic_vector ((12*width)-1 downto 0);        --! Vectores A,B,C,D
34
                prd32blko                               : in    std_logic_vector ((06*width)-1 downto 0);        --! Salidas de los 6 multiplicadores.
35
                add32blko                               : in    std_logic_vector ((04*width)-1 downto 0);        --! Salidas de los 4 sumadores.
36 136 jguarin200
                sqr32blko,inv32blko             : in    std_logic_vector (width-1 downto 0);             --! Salidas de la raiz cuadradas y el inversor.
37 138 jguarin200
                fifo32x23_q                             : in    std_logic_vector (03*width-1 downto 0);          --! Salida de la cola intermedia.
38 127 jguarin200
                fifo32x09_q                             : in    std_logic_vector (02*width-1 downto 0);  --! Salida de las colas de producto punto. 
39
                unary,crossprod,addsub  : in    std_logic;                                                                      --! Bit con el identificador del bloque AB vs CD e identificador del sub bloque (A/B) o (C/D). 
40 145 jguarin200
                sync_chain_0                    : in    std_logic;                                                                      --! Señal de dato valido que se va por toda la cadena de sincronizacion.
41 136 jguarin200
                sqr32blki,inv32blki             : out   std_logic_vector (width-1 downto 0);             --! Salidas de las 2 raices cuadradas y los 2 inversores.
42 127 jguarin200
                fifo32x26_d                             : out   std_logic_vector (03*width-1 downto 0);          --! Entrada a la cola intermedia para la normalizaci&oacute;n.
43
                fifo32x09_d                             : out   std_logic_vector (02*width-1 downto 0);          --! Entrada a las colas intermedias del producto punto.         
44
                prd32blki                               : out   std_logic_vector ((12*width)-1 downto 0);        --! Entrada de los 12 factores en el bloque de multiplicaci&oacute;n respectivamente.
45
                add32blki                               : out   std_logic_vector ((08*width)-1 downto 0);        --! Entrada de los 8 sumandos del bloque de 4 sumadores.  
46 143 jguarin200
                res567w,res13w,res2w    : out   std_logic;                                                                      --! Salidas de escritura y lectura en las colas de resultados.
47
                res0w,res4w,fifo32x09_w : out   std_logic;
48
                fifo32x23_w,fifo32x09_r : out   std_logic;
49
                fifo32x23_r                             : out   std_logic;
50
                res567f,res13f                  : in    std_logic;                                                                      --! Entradas de la se&ntilde;al de full de las colas de resultados. 
51
                res2f,res0f                             : in    std_logic;
52
                resf                                    : out   std_logic;                                                                      --! Salida decodificada que indica que la cola de resultados de la operaci&oacute;n est&aacute; en curso.
53 140 jguarin200
                resultoutput                    : out   std_logic_vector ((08*width)-1 downto 0)         --! 8 salidas de resultados, pues lo m&aacute;ximo que podr&aacute; calcularse por cada clock son 2 vectores. 
54 122 jguarin200
        );
55 123 jguarin200
end dpc;
56 122 jguarin200
 
57 123 jguarin200
architecture dpc_arch of dpc is
58 125 jguarin200
 
59
        constant qz : integer := 00;constant qy : integer := 01;constant qx : integer := 02;
60 123 jguarin200
        constant az : integer := 00;constant ay : integer := 01;constant ax : integer := 02;constant bz : integer := 03;constant by : integer := 04;constant bx : integer := 05;
61
        constant cz : integer := 06;constant cy : integer := 07;constant cx : integer := 08;constant dz : integer := 09;constant dy : integer := 10;constant dx : integer := 11;
62
        constant f0     : integer := 00;constant f1 : integer := 01;constant f2 : integer := 02;constant f3 : integer := 03;constant f4 : integer := 04;constant f5 : integer := 05;
63
        constant f6     : integer := 06;constant f7 : integer := 07;constant f8 : integer := 08;constant f9 : integer := 09;constant f10: integer := 10;constant f11: integer := 11;
64
        constant s0     : integer := 00;constant s1 : integer := 01;constant s2 : integer := 02;constant s3 : integer := 03;constant s4 : integer := 04;constant s5 : integer := 05;
65 127 jguarin200
        constant s6     : integer := 06;constant s7 : integer := 07;
66
        constant a0     : integer := 00;constant a1 : integer := 01;constant a2 : integer := 02;constant aa : integer := 03;
67 123 jguarin200
        constant p0     : integer := 00;constant p1 : integer := 01;constant p2 : integer := 02;constant p3 : integer := 03;constant p4 : integer := 04;constant p5 : integer := 05;
68 127 jguarin200
 
69 124 jguarin200
        constant dpfifoab : integer := 00;
70
        constant dpfifocd : integer := 01;
71
 
72 122 jguarin200
 
73 123 jguarin200
        type    vectorblock12 is array (11 downto 0) of std_logic_vector(width-1 downto 0);
74 127 jguarin200
        type    vectorblock08 is array (07 downto 0) of std_logic_vector(width-1 downto 0);
75 123 jguarin200
        type    vectorblock06 is array (05 downto 0) of std_logic_vector(width-1 downto 0);
76 127 jguarin200
        type    vectorblock04 is array (03 downto 0) of std_logic_vector(width-1 downto 0);
77 124 jguarin200
        type    vectorblock03 is array (02 downto 0) of std_logic_vector(width-1 downto 0);
78 123 jguarin200
        type    vectorblock02 is array (01 downto 0) of std_logic_vector(width-1 downto 0);
79 122 jguarin200
 
80 127 jguarin200
 
81 143 jguarin200
 
82 127 jguarin200
        signal sparaminput,sfactor                      : vectorblock12;
83
        signal ssumando,sresult                         : vectorblock08;
84
        signal sprd32blk                                        : vectorblock06;
85
        signal sadd32blk                                        : vectorblock04;
86 125 jguarin200
        signal snormfifo_q,snormfifo_d          : vectorblock03;
87 127 jguarin200
        signal sdpfifo_q                                        : vectorblock02;
88
        signal ssqr32blk,sinv32blk                      : std_logic_vector(width-1 downto 0);
89 142 jguarin200
        signal ssync_chain                                      : std_logic_vector(28 downto 0);
90 143 jguarin200
        signal ssync_chain_d                            : std_logic;
91
 
92
 
93 140 jguarin200
        constant rstMasterValue : std_logic := '0';
94
 
95 123 jguarin200
begin
96 122 jguarin200
 
97 142 jguarin200
        --! Cadena de sincronizaci&oacute;n: 29 posiciones.
98 145 jguarin200
        ssync_chain(0) <= sync_chain_0;
99 140 jguarin200
        sync_chain_proc:
100
        process(clk,rst)
101
        begin
102
                if rst=rstMasterValue then
103 145 jguarin200
                        ssync_chain(28 downto 1) <= (others => '0');
104 140 jguarin200
                elsif clk'event and clk='1' then
105 142 jguarin200
                        for i in 28 downto 1 loop
106
                                ssync_chain(i) <= ssync_chain(i-1);
107 140 jguarin200
                        end loop;
108
                end if;
109
        end process sync_chain_proc;
110 144 jguarin200
 
111 140 jguarin200
        --! Escritura en las colas de resultados y escritura/lectura en las colas intermedias mediante cadena de resultados.
112 143 jguarin200
        fifo32x09_w <= ssync_chain(5);
113
        fifo32x23_w <= ssync_chain(1);
114
        fifo32x09_r <= ssync_chain(13);
115
        fifo32x23_r <= ssync_chain(24);
116
        res0w <= ssync_chain(23);
117
        res4w <= ssync_chain(21);
118 140 jguarin200
        sync_chain_comb:
119 142 jguarin200
        process (ssync_chain,addsub,crossprod,unary)
120 140 jguarin200
        begin
121
                if unary='1' then
122 143 jguarin200
                        res567w <= ssync_chain(28);
123 140 jguarin200
                else
124 143 jguarin200
                        res567w <= ssync_chain(4);
125 140 jguarin200
                end if;
126 127 jguarin200
 
127 140 jguarin200
                if addsub='1' then
128 143 jguarin200
                        res13w <= ssync_chain(9);
129
                        res2w <= ssync_chain(9);
130 140 jguarin200
                else
131 143 jguarin200
                        res13w <= ssync_chain(13);
132 140 jguarin200
                        if crossprod='1' then
133 143 jguarin200
                                res2w <= ssync_chain(13);
134 140 jguarin200
                        else
135 143 jguarin200
                                res2w <= ssync_chain(22);
136 140 jguarin200
                        end if;
137
                end if;
138
        end process sync_chain_comb;
139
 
140
 
141
        --! El siguiente c&oacute;digo sirve para conectar arreglos a se&ntilde;ales std_logic_1164, simplemente son abstracciones a nivel de c&oacute;digo y no representar&aacute; cambios en la s&iacute;ntesis.
142 123 jguarin200
        stuff12:
143
        for i in 11 downto 0 generate
144
                sparaminput(i) <= paraminput(i*width+width-1 downto i*width);
145
                prd32blki(i*width+width-1 downto i*width) <= sfactor(i);
146 127 jguarin200
        end generate stuff12;
147
        stuff08:
148
        for i in 07 downto 0 generate
149 123 jguarin200
                add32blki(i*width+width-1 downto i*width) <= ssumando(i);
150 127 jguarin200
                resultoutput(i*width+width-1 downto i*width) <= sresult(i);
151
        end generate stuff08;
152 138 jguarin200
        stuff04:
153
        for i in 03 downto 1 generate
154
                sadd32blk(i)  <= add32blko(i*width+width-1 downto i*width);
155
        end generate stuff04;
156
 
157
 
158 124 jguarin200
        stuff03:
159
        for i in 02 downto 0 generate
160 138 jguarin200
                snormfifo_q(i) <= fifo32x23_q(i*width+width-1 downto i*width);
161 124 jguarin200
                fifo32x26_d(i*width+width-1 downto i*width) <= snormfifo_d(i);
162
        end generate stuff03;
163
 
164 123 jguarin200
        stuff02:
165 127 jguarin200
        for i in 01 downto 0 generate
166
                sdpfifo_q(i)  <= fifo32x09_q(i*width+width-1 downto i*width);
167 123 jguarin200
        end generate stuff02;
168 140 jguarin200
 
169
        --! El siguiente c&oacute;digo sirve para conectar arreglos a se&ntilde;ales std_logic_1164, son abstracciones de c&oacute;digo tambi&eacute;n, sin embargo se realizan a trav&eacute;s de registros. 
170
        register_products_outputs:
171
        process (clk)
172
        begin
173
                if clk'event and clk='1' then
174
                        for i in 05 downto 0 loop
175
                                sprd32blk(i)  <= prd32blko(i*width+width-1 downto i*width);
176
                        end loop;
177
                end if;
178
        end process;
179
        --! Los productos del multiplicador 2 y 3, ya registrados dentro de dpc van a la cola intermedia del producto punto (fifo32x09_d)
180 124 jguarin200
        fifo32x09_d <= sprd32blk(p3)&sprd32blk(p2);
181 140 jguarin200
        register_adder0_and_inversor_output:
182
        process (clk)
183
        begin
184
                if clk'event and clk='1' then
185
                        sadd32blk(a0)  <= add32blko(a0*width+width-1 downto a0*width);
186
                        sinv32blk <= inv32blko;
187
                end if;
188
        end process;
189 122 jguarin200
 
190 127 jguarin200
 
191
 
192 140 jguarin200
 
193 144 jguarin200
        --! Raiz Cuadrada.
194 127 jguarin200
        ssqr32blk <= sqr32blko;
195
 
196 136 jguarin200
        --! Colas de salida de los distintos resultados;
197 127 jguarin200
        sresult(0) <= ssqr32blk;
198
        sresult(1) <= sadd32blk(a0);
199
        sresult(2) <= sadd32blk(a1);
200
        sresult(3) <= sadd32blk(a2);
201
        sresult(4) <= sadd32blk(aa);
202
        sresult(5) <= sprd32blk(p3);
203
        sresult(6) <= sprd32blk(p4);
204
        sresult(7) <= sprd32blk(p5);
205
 
206
        --! Cola de normalizacion
207
        snormfifo_d(qx) <= sparaminput(ax);
208
        snormfifo_d(qy) <= sparaminput(ay);
209
        snormfifo_d(qz) <= sparaminput(az);
210
 
211
 
212
 
213 136 jguarin200
        --! La entrada al inversor SIEMPRE viene con la salida de la raiz cuadrada
214
        inv32blki <= sqr32blko;
215 139 jguarin200
        --! La entrada de la ra�z cuadrada SIEMPRE viene con la salida del sumador 1.
216 136 jguarin200
        sqr32blki <= sadd32blk(a1);
217 127 jguarin200
 
218
 
219 136 jguarin200
 
220
        --! Conectar las entradas del sumador a, a la salida 
221
        ssumando(s6) <= sadd32blk(a2);
222
        ssumando(s7) <= sdpfifo_q(dpfifocd);
223
 
224 144 jguarin200
        --!El siguiente proceso conecta la se&ntilde;al de cola "casi llena", de la cola que corresponde al resultado de la operaci&oacute;n indicada por los bit UCA (Unary, Crossprod, Addsub).
225 143 jguarin200
        fullQ:process(res0f,res13f,res2f,res567f,unary,crossprod,addsub)
226
        begin
227
                if unary='0' then
228
                        if crossprod='1' or addsub='1' then
229
                                resf <= res13f;
230
                        else
231
                                resf <= res2f;
232
                        end if;
233
                elsif crossprod='1' or addsub='1' then
234
                        resf <= res567f;
235
                else
236
                        resf <= res0f;
237
                end if;
238
        end process;
239
 
240 144 jguarin200
        --! Decodificaci&oacute;n del Datapath.
241 142 jguarin200
        mul:process(unary,addsub,crossprod,sparaminput,sinv32blk,sprd32blk,sadd32blk,sdpfifo_q,snormfifo_q)
242 123 jguarin200
        begin
243 124 jguarin200
 
244 142 jguarin200
                sfactor(f4) <= sparaminput(az);
245 127 jguarin200
                if unary='1' then
246
                        --! Magnitud y normalizacion
247
                        sfactor(f0) <= sparaminput(ax);
248
                        sfactor(f1) <= sparaminput(ax);
249
                        sfactor(f2) <= sparaminput(ay);
250
                        sfactor(f3) <= sparaminput(ay);
251 142 jguarin200
 
252 127 jguarin200
                        sfactor(f5) <= sparaminput(az);
253 142 jguarin200
                        if crossprod='1' and addsub='1' then
254
                                sfactor(f6) <= sparaminput(cx);
255
                                sfactor(f7) <= sparaminput(dx);
256
                                sfactor(f8) <= sparaminput(cy);
257
                                sfactor(f9) <= sparaminput(dx);
258
                                sfactor(f10) <= sparaminput(cz);
259
                                sfactor(f11) <= sparaminput(dx);
260
                        else
261
                                sfactor(f6) <= snormfifo_q(ax);
262
                                sfactor(f7) <= sinv32blk;
263
                                sfactor(f8) <= snormfifo_q(ay);
264
                                sfactor(f9) <= sinv32blk;
265
                                sfactor(f10) <= snormfifo_q(az);
266
                                sfactor(f11) <= sinv32blk;
267
                        end if;
268
 
269
 
270
                elsif addsub='0' then
271
                        --! Solo productos punto o cruz
272
                        if crossprod='1' then
273
 
274
                                sfactor(f0) <= sparaminput(ay);
275
                                sfactor(f1) <= sparaminput(bz);
276
                                sfactor(f2) <= sparaminput(az);
277
                                sfactor(f3) <= sparaminput(by);
278
 
279
                                sfactor(f5) <= sparaminput(bx);
280
                                sfactor(f6) <= sparaminput(ax);
281
                                sfactor(f7) <= sparaminput(bz);
282
                                sfactor(f8) <= sparaminput(ax);
283
                                sfactor(f9) <= sparaminput(by);
284
                                sfactor(f10) <= sparaminput(ay);
285
                                sfactor(f11) <= sparaminput(bx);
286
 
287
                        else
288
 
289
                                sfactor(f0) <=  sparaminput(ax) ;
290
                                sfactor(f1) <=  sparaminput(bx) ;
291
                                sfactor(f2) <=  sparaminput(ay) ;
292
                                sfactor(f3) <=  sparaminput(by) ;
293
                                sfactor(f5) <=  sparaminput(bz) ;
294
                                sfactor(f6) <=  sparaminput(cx) ;
295
                                sfactor(f7) <=  sparaminput(dx) ;
296
                                sfactor(f8) <=  sparaminput(cy) ;
297
                                sfactor(f9) <=  sparaminput(dy) ;
298
                                sfactor(f10) <= sparaminput(cz) ;
299
                                sfactor(f11) <= sparaminput(dz) ;
300
                        end if;
301
 
302 127 jguarin200
                else
303
                        sfactor(f0) <=  sparaminput(ax) ;
304
                        sfactor(f1) <=  sparaminput(bx) ;
305
                        sfactor(f2) <=  sparaminput(ay) ;
306
                        sfactor(f3) <=  sparaminput(by) ;
307
                        sfactor(f5) <=  sparaminput(bz) ;
308
                        sfactor(f6) <=  sparaminput(cx) ;
309
                        sfactor(f7) <=  sparaminput(dx) ;
310
                        sfactor(f8) <=  sparaminput(cy) ;
311
                        sfactor(f9) <=  sparaminput(dx) ;
312
                        sfactor(f10) <= sparaminput(cz) ;
313
                        sfactor(f11) <= sparaminput(dx) ;
314 125 jguarin200
                end if;
315 127 jguarin200
 
316 136 jguarin200
 
317 127 jguarin200
                if addsub='1' then
318
                        ssumando(s0) <= sparaminput(ax);
319
                        ssumando(s1) <= sparaminput(bx);
320
                        ssumando(s2) <= sparaminput(ay);
321
                        ssumando(s3) <= sparaminput(by);
322
                        ssumando(s4) <= sparaminput(az);
323
                        ssumando(s5) <= sparaminput(bz);
324
                else
325
                        ssumando(s0) <= sprd32blk(p0);
326
                        ssumando(s1) <= sprd32blk(p1);
327 132 jguarin200
                        if crossprod='0' then
328
                                ssumando(s2) <= sadd32blk(a0);
329
                                ssumando(s3) <= sdpfifo_q(dpfifoab);
330
                        else
331
                                ssumando(s2) <= sprd32blk(p2);
332
                                ssumando(s3) <= sprd32blk(p3);
333
                        end if;
334 127 jguarin200
                        ssumando(s4) <= sprd32blk(p4);
335
                        ssumando(s5) <= sprd32blk(p5);
336
                end if;
337 123 jguarin200
        end process;
338
 
339
 
340 127 jguarin200
 
341 123 jguarin200
end dpc_arch;

powered by: WebSVN 2.1.0

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