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

Subversion Repositories jart

[/] [jart/] [branches/] [ver0branch/] [powerGrid.vhd] - Blame information for rev 85

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 jguarin200
-- Author : Julian Andres Guarin Reyes.
2
-- Project : JART, Just Another Ray Tracer.
3
-- email : jguarin2002 at gmail.com, j.guarin at javeriana.edu.co
4
 
5
-- This code was entirely written by Julian Andres Guarin Reyes.
6
-- The following code is licensed under GNU Public License
7
-- http://www.gnu.org/licenses/gpl-3.0.txt.
8
 
9
 -- This file is part of JART (Just Another Ray Tracer).
10
 
11
    -- JART (Just Another Ray Tracer) is free software: you can redistribute it and/or modify
12
    -- it under the terms of the GNU General Public License as published by
13
    -- the Free Software Foundation, either version 3 of the License, or
14
    -- (at your option) any later version.
15
 
16
    -- JART (Just Another Ray Tracer) is distributed in the hope that it will be useful,
17
    -- but WITHOUT ANY WARRANTY; without even the implied warranty of
18
    -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
    -- GNU General Public License for more details.
20
 
21
    -- You should have received a copy of the GNU General Public License
22
    -- along with JART (Just Another Ray Tracer).  If not, see <http://www.gnu.org/licenses/>.
23
 
24
-- 16X50M Intersection Tests    
25
 
26
library ieee;
27
use ieee.std_logic_1164.all;
28
 
29 64 jguarin200
 
30
 
31
 
32 16 jguarin200
package powerGrid is
33 64 jguarin200
 
34
        -- R2 for size and width
35 69 jguarin200
        type SIZE_WIDTH is array (integer,integer) of integer;
36
        type DUPLA is array (0 to 2,1 downto 0) of integer;
37 64 jguarin200
 
38
        -- Tuple for widths
39
        type WARRAY is array (0 to 2) of integer;
40
 
41
        -- Index 
42 69 jguarin200
        constant SZINDEX: integer :=0;   -- Size Description Index.
43
        constant WDINDEX: integer :=1;  -- Width description Index.
44 64 jguarin200
 
45
        -- Register file for spheres.
46
        -- OP1 : One sphere output per clock.
47
        -- OP2 : Two sphere output per clock.
48
        -- OP4 : Four sphere output per clock.
49
        constant OP4            : integer := 2;
50
        constant OP2            : integer := 1;
51
        constant OP1            : integer := 0;
52
 
53
        constant SZALFA         : integer := 1;
54
        constant SZBETA         : integer := 2;
55
 
56 69 jguarin200
        constant DBUSW          : integer := 64;
57 64 jguarin200
        constant BUSW           : integer := 32;
58
        constant HBUSW          : integer := 18;
59
 
60 69 jguarin200
        -- Size and Width depending upon the number of spheres to push out in one clock (OP1= One sphere, OP2 = Two spheres, OP4= Four spheres).
61 64 jguarin200
        constant REGSZADD       : WARRAY := (12,11,10);
62
        constant CIDSZADD       : DUPLA := ((1,0),(2,1),(4,2));
63
 
64 85 jguarin200
 
65
        -- Decimal Fix is a component used after normalization (unitary vector calculation), when you want to assure that your A(n,10) number is representing a (-1,1) number. For that matter and  precission issues, your unitary vector component may go beyond bounds, lower than -1 or greater than 1. After executing a square root or a division, where the result must be between -1 and 1, you can have little misscalculation, for example 1.0004+ or -1.0004-. There's no way to know how much the error is, but for sure we can minimize it. We can push up a 1.0004- to -1, and pull down a 1.0004+ to 0.999023.
66
 
67
 
68
        component decimalFix
69
        generic
70
        (
71
                bigdecimal              : integer := 16;
72
                litdecimal              : integer := 10;
73
                litinteger              : integer := 7
74
 
75
        );
76
        port (
77
 
78
                clk, rst, ena   : in std_logic; -- The usual control signals
79
                inputsign,ovf   : in std_logic; -- Sign bit and overflow bit, the overflow bit is usually the less significant one in the integer bit set.
80
                outputsign              : out std_logic; -- Sign at output.
81
                inputdecimal    : in std_logic_vector (bigdecimal-1 downto 0); -- The 16 bit decimal (by default) decimal entering
82
                outputdecimal   : out std_logic_vector (litdecimal-1 downto 0) -- The 10 bit decimal at output.
83
 
84
 
85
 
86
        );
87
 
88
        end component;
89 80 jguarin200
        -- Unitary Ray Set. 
90
        -- Y component generation.
91
        component yu
92
                generic (
93
 
94 85 jguarin200
                -- Define the max counting number.. the number must be expressed as 2 power, cause the range of counting is going to be defined as top-1 downto top/2.
95 80 jguarin200
                -- However this is going to be by now, cause in the future the ray generation will GO on for higher resolution images , and perhaps it would be required a more extended range for the yu component.
96 85 jguarin200
                TOP : integer := 1024;
97 80 jguarin200
                SCREENW : integer := 320
98
                );
99
                port (
100
                clk,rst,ena             : in std_logic;
101
                lineDone                : out std_logic;
102
                ypos                    : out integer range TOP/2 to TOP-1
103
                );
104
        end component;
105
        -- Z and X component generation
106
        component zu
107
                generic
108
                (
109
                VALSTART                : integer := 9
110
                );
111
                port (
112
 
113
                clk,rst,ena     : in std_logic; -- The usual control signals
114
                clr                             : in std_logic;
115
                zpos                    : out integer range -1024 to 1023;
116
                zneg                    : out integer range -1024 to 1023
117
                );
118
        end component;
119 64 jguarin200
 
120
 
121
        -- Register blocks.....
122
 
123
        -- 8 x 512 x 32 
124
        component bt81
125
                port
126
                (
127
                address         : in std_logic_vector (11 downto 0);
128
                clken           : in std_logic ;
129
                clock           : in std_logic ;
130
                data            : in std_logic_vector (31 downto 0);
131
                wren            : in std_logic ;
132
                q                       : out std_logic_vector (31 downto 0)
133
                );
134
        end component;
135
 
136
        -- 4 x 512 x 32 
137
        component bt41
138
                port
139
                (
140
                address         : in std_logic_vector (10 downto 0);
141
                clken           : in std_logic ;
142
                clock           : in std_logic ;
143
                data            : in std_logic_vector (31 downto 0);
144
                wren            : in std_logic ;
145
                q                       : out std_logic_vector (31 downto 0)
146
                );
147
        end component;
148
 
149
        -- 2 x 512 x 32 
150
        component bt21
151
                port
152
                (
153
                address         : in std_logic_vector (9 downto 0);
154
                clken           : in std_logic ;
155
                clock           : in std_logic ;
156
                data            : in std_logic_vector (31 downto 0);
157
                wren            : in std_logic ;
158
                q                       : out std_logic_vector (31 downto 0)
159
                );
160
        end component;
161
 
162
        -- 1 x 512 x 32 
163 66 jguarin200
        component bt11
164 64 jguarin200
                port
165
                (
166
                address         : in std_logic_vector (8 downto 0);
167
                clken           : in std_logic ;
168
                clock           : in std_logic ;
169
                data            : in std_logic_vector (31 downto 0);
170
                wren            : in std_logic ;
171
                q                       : out std_logic_vector (31 downto 0)
172
                );
173
        end component;
174
 
175 67 jguarin200
        -- 8 x 512 x 18 
176 64 jguarin200
        component bt84
177
                port
178
                (
179
                address         : in std_logic_vector (11 downto 0);
180
                clken           : in std_logic ;
181
                clock           : in std_logic ;
182
                data            : in std_logic_vector (17 downto 0);
183
                wren            : in std_logic ;
184
                q                       : out std_logic_vector (17 downto 0)
185
                );
186
        end component;
187
 
188 66 jguarin200
        -- 4 x 512 x 18 
189 64 jguarin200
        component bt44
190
                port
191
                (
192
                address         : in std_logic_vector (10 downto 0);
193
                clken           : in std_logic ;
194
                clock           : in std_logic ;
195
                data            : in std_logic_vector (17 downto 0);
196
                wren            : in std_logic ;
197
                q                       : out std_logic_vector (17 downto 0)
198
                );
199
        end component;
200
 
201 66 jguarin200
        -- 2 x 512 x 18 
202 64 jguarin200
        component bt24
203
                port
204
                (
205
                address         : in std_logic_vector (9 downto 0);
206
                clken           : in std_logic ;
207
                clock           : in std_logic ;
208
                data            : in std_logic_vector (17 downto 0);
209
                wren            : in std_logic ;
210
                q                       : out std_logic_vector (17 downto 0)
211
                );
212
        end component;
213
 
214
        -- 1 x 512 x 18 
215
        component bt14
216
                port
217
                (
218
                address         : in std_logic_vector (8 downto 0);
219
                clken           : in std_logic ;
220
                clock           : in std_logic ;
221
                data            : in std_logic_vector (17 downto 0);
222
                wren            : in std_logic ;
223
                q                       : out std_logic_vector (17 downto 0)
224
                );
225
        end component;
226
 
227
        -- Register type 1 .
228
        component r1
229
                port (
230
 
231
 
232
                        clk, ena: in std_logic; -- The usual control signals.
233
 
234
                        wen             : in std_logic_vector   (3 downto 0);
235
                        add             : in std_logic_vector   (8 downto 0);
236
                        datain  : in std_logic_vector   (BUSW-1 downto 0);-- incoming data from 32 bits width bus.
237
                        Vx              : out std_logic_vector  (HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
238
                        Vy              : out std_logic_vector  (HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
239
                        Vz              : out std_logic_vector  (HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
240
                        K               : out std_logic_vector  (BUSW-1 downto 0)
241
                );
242
        end component;
243
        -- Register type 2 .
244
        component r2
245
                port (
246
 
247
 
248
                        clk, ena: in std_logic; -- The usual control signals.
249
 
250
                        wen             : in std_logic_vector   (3 downto 0);
251
                        add             : in std_logic_vector   (9 downto 0);
252
                        datain  : in std_logic_vector   (BUSW-1 downto 0);-- incoming data from 32 bits width bus.
253
                        Vx              : out std_logic_vector  (HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
254
                        Vy              : out std_logic_vector  (HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
255
                        Vz              : out std_logic_vector  (HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
256
                        K               : out std_logic_vector  (BUSW-1 downto 0)
257
                );
258
        end component;
259
        -- Register type 4
260
        component r4
261
                port (
262
 
263
 
264
                        clk, ena: in std_logic; -- The usual control signals.
265
 
266
                        wen             : in std_logic_vector   (3 downto 0);
267
                        add             : in std_logic_vector   (10 downto 0);
268
                        datain  : in std_logic_vector   (BUSW-1 downto 0);-- incoming data from 32 bits width bus.
269
                        Vx              : out std_logic_vector  (HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
270
                        Vy              : out std_logic_vector  (HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
271
                        Vz              : out std_logic_vector  (HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
272
                        K               : out std_logic_vector  (BUSW-1 downto 0)
273
                );
274
        end component;-- Register type 8.
275
        component r8
276
                port (
277
 
278
 
279
                        clk, ena: in std_logic; -- The usual control signals.
280
 
281
                        wen             : in std_logic_vector   (3 downto 0);
282
                        add             : in std_logic_vector   (11 downto 0);
283
                        datain  : in std_logic_vector   (BUSW-1 downto 0);-- incoming data from 32 bits width bus.
284
                        Vx              : out std_logic_vector  (HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
285
                        Vy              : out std_logic_vector  (HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
286
                        Vz              : out std_logic_vector  (HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
287
                        K               : out std_logic_vector  (BUSW-1 downto 0)
288
                );
289
        end component;
290
 
291
 
292
        -- Register Option mode 1
293
        component rop1
294
                generic (
295
                        SZMODE  : integer       := SZBETA       -- By default use the 50% of the max memory for sphere register block.
296
                );
297
                port (
298
 
299
 
300
                        clk, ena: in std_logic; -- The usual control signals.
301
                        wen             : in std_logic_vector   (3 downto 0);
302
                        add             : in std_logic_vector   (REGSZADD(OP1)-SZMODE downto 0);
303
                        datain  : in std_logic_vector   (BUSW-1 downto 0);-- incoming data from 32 bits width bus.
304
                        Vx              : out std_logic_vector  (2*HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
305
                        Vy              : out std_logic_vector  (2*HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
306
                        Vz              : out std_logic_vector  (2*HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
307
                        K               : out std_logic_vector  (2*BUSW-1 downto 0)
308
                );
309
 
310
        end component;
311
 
312
        -- Register Option mode 2
313
        component rop2
314
                generic (
315
                        SZMODE  : integer       := SZBETA       -- By default use the 50% of the max memory for sphere register block.
316
                );
317
                port (
318
 
319
 
320
                        clk, ena: in std_logic; -- The usual control signals.
321
                        wen             : in std_logic_vector   (7 downto 0);
322
                        add             : in std_logic_vector   (REGSZADD(OP2)-SZMODE downto 0);
323
                        datain  : in std_logic_vector   (BUSW-1 downto 0);-- incoming data from 32 bits width bus.
324
                        Vx              : out std_logic_vector  (2*HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
325
                        Vy              : out std_logic_vector  (2*HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
326
                        Vz              : out std_logic_vector  (2*HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
327
                        K               : out std_logic_vector  (2*BUSW-1 downto 0)
328
                );
329
 
330
        end component;
331
 
332
        -- Register Option mode 2
333
        component rop4
334
                generic (
335
                        SZMODE  : integer       := SZBETA       -- By default use the 50% of the max memory for sphere register block.
336
                );
337
                port (
338
 
339
 
340
                        clk, ena: in std_logic; -- The usual control signals.
341
                        wen             : in std_logic_vector   (15 downto 0);
342
                        add             : in std_logic_vector   (REGSZADD(OP4)-SZMODE downto 0);
343
                        datain  : in std_logic_vector   (BUSW-1 downto 0);-- incoming data from 32 bits width bus.
344
                        Vx              : out std_logic_vector  (4*HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
345
                        Vy              : out std_logic_vector  (4*HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
346
                        Vz              : out std_logic_vector  (4*HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
347
                        K               : out std_logic_vector  (4*BUSW-1 downto 0)
348
                );
349
 
350
        end component;
351
 
352
 
353
        -- Sphere Register Block
354
        component sphereRegisterBlock
355
                generic (
356
 
357
                        OPMODE  : integer := OP4;               -- By default push out 4 spheres at same time.
358 69 jguarin200
                        SZMODE  : integer := SZBETA             -- By default the max sphere numbers is 2048, but could be 4096 with SZALFA.
359
 
360
 
361 64 jguarin200
                );
362
                port (
363
 
364
 
365
                        clk, ena: in std_logic; -- The usual control signals.
366
 
367 69 jguarin200
                        wen             : in std_logic_vector   (CIDSZADD(OP4,SZINDEX)-1 downto 0);      -- Write enable signals
368 64 jguarin200
                        add             : in std_logic_vector   (REGSZADD(OPMODE)-SZMODE  downto 0);             -- Address bus
369
 
370
                        datain  : in std_logic_vector   (BUSW-1 downto 0);       -- incoming data from 32 bits width bus.
371
 
372
                        Vx              : out std_logic_vector  (OPMODE*HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
373
                        Vy              : out std_logic_vector  (OPMODE*HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
374
                        Vz              : out std_logic_vector  (OPMODE*HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
375
                        K               : out std_logic_vector  (OPMODE*BUSW-1 downto 0)
376
 
377
                );
378
 
379 69 jguarin200
        end component;
380 64 jguarin200
 
381 58 jguarin200
        -- A scan flip flop, aka selectable input ff.
382
        component scanFF
383
                generic (
384
                W       : integer := 8);
385
                port    (
386 61 jguarin200
                clk,rst,ena,sel         : in std_logic; -- The usual  control signals
387 58 jguarin200
 
388 61 jguarin200
                d0,d1   : in std_logic_vector (W-1 downto 0);    -- The two operands.
389
                q               : out std_logic_vector (W-1 downto 0)    -- The selected data.
390 58 jguarin200
 
391
                );
392
        end component;
393 33 jguarin200
        --A one stage pipe (1 Clk) a+b+c with w width bits in input as well as output.
394
        --As a fixed signed addtion we have:
395
        -- A(B,C) ====> B+C SIGNED BITS FORMAT : 1 bit for sign, B bits for integer part, C bits for decimal part. (FORMAT)
396
        -- A(15,20)*A(15,20) = A(15,20). (This component format)
397
 
398 22 jguarin200
        component p1ax
399 33 jguarin200
                generic (
400
                -- The width of the operands and result.
401
                W               : integer := 36 );
402
                port    (
403
                -- The usual control signals.
404
                clk             :        in std_logic;
405
                rst             :        in std_logic;
406 61 jguarin200
                enable  :        in std_logic;
407 33 jguarin200
 
408
                -- Operand A.
409
                dataa           :        in std_logic_vector(W-1 downto 0);
410
                -- Operand B.
411
                datab           :        in std_logic_vector(W-1 downto 0);
412
                -- Operand C
413
                datac           :        in std_logic_vector(W-1 downto 0);
414
                -- Result.
415
                result          :        out std_logic_vector(W-1 downto 0)
416 22 jguarin200
                );
417
        end component;
418
 
419
        -- A 1 stage pipe 18x18 multiplier. On Cycle III devices is a M-R (Multiplier, Register). (Should be generated using a synthesis tool....).
420 33 jguarin200
        -- As a fixed signed multiplication we have :
421
        -- A(B,C) ====> B+C SIGNED BITS FORMAT : 1 bit for sign, B bits for integer part, C bits for decimal part. (FORMAT)
422
        -- A(7,10)*A(7,10) = A(15,20). (This component format)
423
 
424 22 jguarin200
        component p1m18
425
                port    (
426 33 jguarin200
                -- Asynchronous clear signal.
427
                aclr            : in std_logic ;
428
                -- The usual control signals.
429
                clken           : in std_logic ;
430
                clock           : in std_logic ;
431
 
432
                -- Factor A.
433
                dataa           : in std_logic_vector (17 downto 0);
434
                -- Factor B.
435
                datab           : in std_logic_vector (17 downto 0);
436
                -- Product.
437
                result          : out std_logic_vector (35 downto 0)
438 22 jguarin200
                );
439
        end component;
440
 
441 33 jguarin200
        -- Signed "less than". dataa < datab
442 16 jguarin200
        component sl32
443
                port    (
444 33 jguarin200
 
445
                dataa   : in std_logic_vector (31 downto 0);
446
                datab   : in std_logic_vector (31 downto 0);
447
                AlB             : out std_logic
448
 
449 16 jguarin200
                );
450
                end component;
451
 
452 33 jguarin200
        -- Signed "greater than". dataa >= datab.
453 16 jguarin200
        component sge32
454
                port    (
455 33 jguarin200
 
456
                dataa   : in std_logic_vector (31 downto 0);
457
                datab   : in std_logic_vector (31 downto 0);
458
                AgeB    : out std_logic
459
 
460 16 jguarin200
                );
461
                end component;
462
 
463
 
464 22 jguarin200
        -- Dot Product Calculation Cell. 
465
        -- A 4 side cell along with an upper side. 
466
        -- V input flows through V output using a data flipflop, so turning V output in the next cell on the next row V Input. V input also flows upwards into the dotproduct 3 stage pipeline. 
467
        -- D input flows through D output using a data flipflop, so turning D output in the next column cell. D input also flows upwards into the dotproduct 3 stage. 
468 16 jguarin200
        component dotCell
469 40 jguarin200
                generic (
470
 
471
                -- Register V?, by default register the pass of V to the next grid. This should be NO when using a single grid cube or in the last grid of the grid array.
472
                RV      : string := "yes";
473 33 jguarin200
                -- Actual Level Width
474 40 jguarin200
                W0      : integer := 18;
475 33 jguarin200
                -- Next Level Width
476 40 jguarin200
                W1      : integer := 32);
477 33 jguarin200
 
478 16 jguarin200
                port    (
479 33 jguarin200
                --The usual control signals
480
                clk                     : in std_logic;
481
                rst                     : in std_logic;
482 16 jguarin200
 
483 33 jguarin200
                -- This bit controls when the sphere center goes to the next row.
484
                nxtSphere       : in std_logic;
485
                -- This bit controls when the ray goes to the next column.
486
                nxtRay          : in std_logic;
487 22 jguarin200
 
488 33 jguarin200
                -- First Side.
489 40 jguarin200
                vxInput         : in std_logic_vector(W0-1 downto 0);
490
                vyInput         : in std_logic_vector(W0-1 downto 0);
491
                vzInput         : in std_logic_vector(W0-1 downto 0);
492 16 jguarin200
 
493 33 jguarin200
                -- Second Side (Opposite to the first one)
494 40 jguarin200
                vxOutput        : out std_logic_vector(W0-1 downto 0);
495
                vyOutput        : out std_logic_vector(W0-1 downto 0);
496
                vzOutput        : out std_logic_vector(W0-1 downto 0);
497 16 jguarin200
 
498 33 jguarin200
                -- Third Side (Perpendicular to the first and second ones)
499 40 jguarin200
                dxInput         : in std_logic_vector(W0-1 downto 0);
500
                dyInput         : in std_logic_vector(W0-1 downto 0);
501
                dzInput         : in std_logic_vector(W0-1 downto 0);
502 16 jguarin200
 
503 33 jguarin200
                --Fourth Side (Opposite to the third one)
504 64 jguarin200
                dxOutput        : out std_logic_vector(W0-1 downto 0);
505
                dyOutput        : out std_logic_vector(W0-1 downto 0);
506
                dzOutput        : out std_logic_vector(W0-1 downto 0);
507 16 jguarin200
 
508 33 jguarin200
                --Fifth Side (Going to the floor right upstairs!)
509 40 jguarin200
                vdOutput        : out std_logic_vector(W1-1 downto 0) -- Dot product.
510 16 jguarin200
 
511 22 jguarin200
                );
512 16 jguarin200
        end component;
513
 
514
        -- K discriminant comparison.
515 33 jguarin200
        -- The vdinput value is the calculation of the ray and the column's sphere dot product. This value should be compared to a sphere constant in order to find out whether the ray intersects
516
        -- or not the sphere. If vdinput is grather or equal than kinput there's an intersection or else when vdinput is less than kinput. If there's an intersection the block sets vdinput at vdoutput,
517
        -- whenever there's no intersection the output is asserted with the maximum positive distance in 32 bits : 0x7fffffff.
518 16 jguarin200
        component kComparisonCell
519 40 jguarin200
                generic (
520
                RK      : string        := "yes";
521
                W1      : integer       := 32
522 16 jguarin200
                );
523 40 jguarin200
                port (
524
                clk,rst         : in std_logic;
525
                scanOut         : in std_logic; -- This signals overrides the 'signed greater or equal than' internal function and allows vdinput to flow upwards.
526
                nxtSphere       : in std_logic; -- Controls when the sphere goes to the next Row. 
527
                pipeOn          : in std_logic; -- Enables / Disable the upwarding flow.
528
                kinput          : in std_logic_vector (W1-1 downto 0);
529
                koutputhor      : out std_logic_vector (W1-1 downto 0);
530
                koutputver      : out std_logic_vector (W1-1 downto 0);  -- K input  flowing to the next floor upstairs (but waits one clock). 
531
                vdinput         : in std_logic_vector (W1-1 downto 0);   -- V.D input.
532
                vdoutput        : out std_logic_vector (W1-1 downto 0)   -- Selected dot product.
533
                );
534 22 jguarin200
        end component;
535 33 jguarin200
        -- Minimun distance Comparison.
536
        -- The reference value, refvd, is the ray minimal intersection distance calculated in the moment of the comparison. 
537
        -- The column value, colvd, is the column sphere and ray intersection distance (if any or else the maximum distance is asserted).
538
 
539
 
540
        component dComparisonCell
541
                generic (
542
                -- V.D, minDistance and selectD Width 
543 40 jguarin200
                W1              : integer := 32;
544 33 jguarin200
                -- Column Sphere ID width. 1 = 2 columns max, 2= 4 colums max... and so on.
545 40 jguarin200
                IDW     : integer := 2;
546 33 jguarin200
                -- Column Id
547
                idCol   : integer := 0
548
                );
549
                port    (
550
                -- The usual control signals.           
551 40 jguarin200
                clk, rst, pipeOn : in std_logic;
552
 
553 61 jguarin200
 
554
                intd    : in    std_logic;
555
                intq    : out   std_logic;
556 33 jguarin200
                -- This is the reference column identification input.
557 40 jguarin200
                cIdd    : in    std_logic_vector (IDW - 1 downto 0);
558 33 jguarin200
                -- This is the result column identification output.
559 61 jguarin200
                cIdq    : out   std_logic_vector (IDW - 1 downto 0);
560
                refk    : in    std_logic_vector (W1 - 1 downto 0); -- This is the columns sphere constant
561
                colk    : in    std_logic_vector (W1 - 1 downto 0); -- This is the reference sphere constant
562
                selk    : out   std_logic_vector (W1 - 1 downto 0); -- This is the selected sphere constant              
563 33 jguarin200
                -- This is the reference projection incoming from the previous cell.
564 40 jguarin200
                refvd   : in    std_logic_vector (W1 - 1 downto 0);
565 33 jguarin200
                -- This is the sphere position over the ray traced vector projection.
566 40 jguarin200
                colvd   : in    std_logic_vector (W1 - 1 downto 0);
567 33 jguarin200
                -- This is the smallest value between refvd and colvd.
568 40 jguarin200
                selvd   : out   std_logic_vector (W1 - 1 downto 0)
569 33 jguarin200
                );
570
        end component;
571
 
572
        component floor0Row
573
                generic (
574
                -- Floor Level Width (V.D width)
575 40 jguarin200
                W1 : integer := 32;
576 33 jguarin200
                -- Vector input Width           
577 40 jguarin200
                W0 : integer := 18;
578 33 jguarin200
                -- Number of Colums
579 40 jguarin200
                C       : integer := 4
580 33 jguarin200
        );
581
        port (
582
                -- The usual control signals. nxtRay should be 0 whenever I want to stop the entire machine.
583
                clk, rst, nxtRay : in std_logic;
584 16 jguarin200
 
585 33 jguarin200
                -- Clk, Rst, the usual control signals.
586
                -- enabled, the machine is running when this input is set.
587
                -- enabled, all the counters begin again.
588 40 jguarin200
                nxtSphere : in std_logic_vector (C-1 downto 0);
589 33 jguarin200
 
590
 
591
                -- Input Values. 
592
                -- The ray input vector.
593 40 jguarin200
                iRayx: in std_logic_vector (W0 - 1 downto 0);
594
                iRayy: in std_logic_vector (W0 - 1 downto 0);
595
                iRayz: in std_logic_vector (W0 - 1 downto 0);
596 33 jguarin200
 
597
                -- The spheres x position (sphere centers) input vectors.
598 40 jguarin200
                iSphrCenterx: in std_logic_vector (C*W0 - 1 downto 0);
599 33 jguarin200
                -- The spheres y position (sphere centers) input vectors.
600 40 jguarin200
                iSphrCentery: in std_logic_vector (C*W0 - 1 downto 0);
601 33 jguarin200
                -- The spheres z position (sphere centers) input vectors.
602 40 jguarin200
                iSphrCenterz: in std_logic_vector (C*W0 - 1 downto 0);
603 33 jguarin200
                -- The spheres x position (sphere centers) output vectors.
604 40 jguarin200
                oSphrCenterx: out std_logic_vector (C*W0 - 1 downto 0);
605 33 jguarin200
                -- The spheres y positions (sphere centes) output vectors.
606 40 jguarin200
                oSphrCentery: out std_logic_vector (C*W0 - 1 downto 0);
607 33 jguarin200
                -- The spheres z positions (sphere centers) output vectors.             
608 40 jguarin200
                oSphrCenterz: out std_logic_vector (C*W0 - 1 downto 0);
609 33 jguarin200
 
610
                -- Output Values
611
                -- The ray output vector.
612 40 jguarin200
                oRayx: out std_logic_vector (W0 - 1 downto 0);
613
                oRayy: out std_logic_vector (W0 - 1 downto 0);
614
                oRayz: out std_logic_vector (W0 - 1 downto 0);
615 33 jguarin200
 
616
                -- The dot product result from each dot prod cell.
617 40 jguarin200
                vdOutput : out std_logic_vector (W1*C - 1 downto 0)
618 33 jguarin200
                );
619
        end component;
620
 
621
        -- In this level the V.D results from floor 0 are compared whether they are greater or equal than column's sphere K constants, in order to find if there's an intersection per column or not.
622
        -- When any comparison is true, meaning VD value greater or equal than K, the outgoing value to floor2 level is the same VD, if not the outgoing value is 0x7fffffff (the maximum)
623
        -- distance value.
624
 
625
        component floor1Row
626
        generic (
627
 
628
                -- Vector input Width   
629 40 jguarin200
                W1 : integer := 32;
630 33 jguarin200
                -- Number of Colums
631 40 jguarin200
                C       : integer := 4
632 33 jguarin200
        );
633
        port (
634
 
635
                -- Input Control Signals, pipe on is one when raysr going on. 
636
                clk, rst        : in std_logic;
637
                pipeOn          : in std_logic;
638
 
639
                -- Clk, Rst, the usual control signals.
640 40 jguarin200
                nxtSphere       : in std_logic_vector (C-1 downto 0);
641 33 jguarin200
 
642
                -- VD Input / Output.
643 40 jguarin200
                vdInput : in std_logic_vector (W1*C-1 downto 0);
644
                vdOutput: out std_logic_vector (W1*C-1 downto 0);
645 33 jguarin200
 
646
                -- K Input / Output.
647 40 jguarin200
                kInput  : in std_logic_vector (W1*C - 1 downto 0);
648
                kOutput : out std_logic_vector (W1*C - 1 downto 0)
649 33 jguarin200
        );
650
        end component;
651
 
652
        -- This level takes the -on the moment smalles distance-- value per ray in the extreme left, and starts making comparisons from left to right, one comparison each clock and so on, searching for the smallest V.D value in the row incomung from the floor1 level. When the ray has finished crossing throguh all the spheres in the scene, the row extreme right value will be the smallest V.D found along with an ID of the sphere intersected. This is the goal of the intersection architecture : to find out which is the closest sphere intersected by a particular ray. 
653
 
654
        component floor2Row
655
        generic (
656
                -- Vector input Width
657 40 jguarin200
                W1 : integer := 32;
658 33 jguarin200
                -- ID Column width
659 40 jguarin200
                IDW : integer := 2;
660 33 jguarin200
                -- Number of Colums
661 40 jguarin200
                C       : integer := 4
662 33 jguarin200
        );
663
        port (
664
                -- Input Control Signal
665
                -- Clk, Rst, the usual control signals.
666
                clk, rst, pipeOn: in std_logic;
667
 
668
                -- Input Values
669
                -- Reference VD, the "at the moment" smallest VD sphere ray projection value.
670 40 jguarin200
                refvd   : in std_logic_vector (W1-1 downto 0);
671 33 jguarin200
 
672
                -- The smallest VD, value found.
673 40 jguarin200
                selvd   : out std_logic_vector (W1-1 downto 0);
674 33 jguarin200
 
675
                -- The column's sphere ray projection value.
676 40 jguarin200
                colvd   : in std_logic_vector (W1*C-1 downto 0);
677 33 jguarin200
                -- The smallest VD projection value column id.
678 40 jguarin200
                colid   : out std_logic_vector (IDW-1 downto 0);
679 33 jguarin200
                -- The intersection signal (1 on intersection else 0).
680
                inter   : out std_logic
681
        );
682
        end component;
683
 
684
        component rayxsphereGrid
685
        generic (
686
                -- Width of Column identificator.
687
                IDW     : integer := 2;
688
                -- Number of Columns.
689
                C       : integer := 4;
690
                -- Input rays width.
691
                W0      : integer := 18;
692
                -- Dot products and spheres constant width
693 40 jguarin200
                W1      : integer := 32
694 33 jguarin200
 
695
                );
696
        port (
697
                -- The usual control signals.
698
                clk,rst         : in std_logic;
699
 
700
                -- Grid, rays and sphere flow through control signals.
701
                pipeOn          : in std_logic;
702
                nxtSphere       : in std_logic_vector (C-1 downto 0);
703
 
704
                -- R-F0
705
                -- Input Values. 
706
                -- The ray input vector.
707
                iRayx: in std_logic_vector (W0 - 1 downto 0);
708
                iRayy: in std_logic_vector (W0 - 1 downto 0);
709
                iRayz: in std_logic_vector (W0 - 1 downto 0);
710
                -- The spheres x position (sphere centers) input vectors.
711
                iSphrCenterx: in std_logic_vector (C*W0 - 1 downto 0);
712
                -- The spheres y position (sphere centers) input vectors.
713
                iSphrCentery: in std_logic_vector (C*W0 - 1 downto 0);
714
                -- The spheres z position (sphere centers) input vectors.
715
                iSphrCenterz: in std_logic_vector (C*W0 - 1 downto 0);
716
                -- The spheres x position (sphere centers) output vectors.
717
                oSphrCenterx: out std_logic_vector (C*W0 - 1 downto 0);
718
                -- The spheres y positions (sphere centes) output vectors.
719
                oSphrCentery: out std_logic_vector (C*W0 - 1 downto 0);
720
                -- The spheres z positions (sphere centers) output vectors.             
721
                oSphrCenterz: out std_logic_vector (C*W0 - 1 downto 0);
722
                -- Output Values
723
                -- The ray output vector.
724
                oRayx: out std_logic_vector (W0 - 1 downto 0);
725
                oRayy: out std_logic_vector (W0 - 1 downto 0);
726
                oRayz: out std_logic_vector (W0 - 1 downto 0);
727
 
728
                -- R-F1
729
                -- K Input / Output.
730
                kInput  : in std_logic_vector (C*W1 - 1 downto 0);
731 40 jguarin200
                kOutput : out std_logic_vector (C*W1 - 1 downto 0);
732 33 jguarin200
 
733
                --R-F2
734
                -- Input Values
735
                refvd   : in std_logic_vector (W1-1 downto 0);
736
                selvd   : out std_logic_vector (W1-1 downto 0);
737
                colid   : out std_logic_vector (IDW-1 downto 0);
738
                inter   : out std_logic
739
                );
740
        end component;
741
        component gridCube
742
        generic (
743
                -- Depth
744
                D       : integer := 4;
745
                -- ID width.
746
                IDW     : integer := 2;
747
                -- Number of Columns.
748
                C       : integer := 4;
749
                -- Input rays width.
750
                W0      : integer := 18;
751
                -- Dot products and spheres constant width
752 40 jguarin200
                W1      : integer := 32
753 33 jguarin200
 
754
                );
755
        port (
756
                        -- The usual control signals.
757
                clk,rst : in std_logic;
758
 
759
                -- Grid, rays and sphere flow through control signals.
760
                pipeOn                  : in std_logic;
761
                -- The same column nxtSphere signal control..... regardless the Cube Depth.
762
                nxtSphere               : in std_logic_vector (C-1 downto 0);
763
 
764
                -- R-F0
765
                -- Input Values. 
766
                -- The ray input vector. 
767
                iRayx: in std_logic_vector (D*W0 - 1 downto 0);
768
                iRayy: in std_logic_vector (D*W0 - 1 downto 0);
769
                iRayz: in std_logic_vector (D*W0 - 1 downto 0);
770
                -- The spheres x position (sphere centers) input vectors.
771
                iSphrCenterx: in std_logic_vector (C*W0 - 1 downto 0);
772
                -- The spheres y position (sphere centers) input vectors.
773
                iSphrCentery: in std_logic_vector (C*W0 - 1 downto 0);
774
                -- The spheres z position (sphere centers) input vectors.
775
                iSphrCenterz: in std_logic_vector (C*W0 - 1 downto 0);
776
                -- The spheres x position (sphere centers) output vectors.
777
                oSphrCenterx: out std_logic_vector (C*W0 - 1 downto 0);
778
                -- The spheres y positions (sphere centes) output vectors.
779
                oSphrCentery: out std_logic_vector (C*W0 - 1 downto 0);
780
                -- The spheres z positions (sphere centers) output vectors.             
781
                oSphrCenterz: out std_logic_vector (C*W0 - 1 downto 0);
782
                -- Output Values
783
                -- The ray output vector.
784
                oRayx: out std_logic_vector (D*W0 - 1 downto 0);
785
                oRayy: out std_logic_vector (D*W0 - 1 downto 0);
786
                oRayz: out std_logic_vector (D*W0 - 1 downto 0);
787
 
788
                -- R-F1
789
                -- K Input / Output.
790
                kInput  : in std_logic_vector (C*W1 - 1 downto 0);
791 40 jguarin200
                kOutput : out std_logic_vector (C*W1 - 1 downto 0);
792 33 jguarin200
 
793
                --R-F2
794
                -- Input Values
795
                refvd   : in std_logic_vector (D*W1-1 downto 0);
796
                selvd   : out std_logic_vector (D*W1-1 downto 0);
797
                colid   : out std_logic_vector (D*IDW-1 downto 0);
798
                inter   : out std_logic_vector (D-1 downto 0)
799
                );
800
        end component;
801 80 jguarin200
 
802
        function mylog2( x : in integer; s: string) return integer;
803
 
804
end powerGrid;
805
package body powerGrid is
806
        function mylog2(x: integer; s : string) return integer is
807
                variable accum : integer :=1;
808
                variable i         : integer range 0 to 32 := 1;
809
        begin
810
 
811
                while (accum<=x) loop
812
                        accum   := accum*2;
813
                        i               := i+1;
814
                end loop;
815
                if s="unsigned" then
816
                        return i-1;
817
                else
818
                        return i;
819
                end if;
820
        end;
821
 
822
end package body;

powered by: WebSVN 2.1.0

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