1 |
17 |
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 |
|
|
-- A single fixed minimun distance comparison cell.
|
25 |
14 |
jguarin200 |
library ieee;
|
26 |
|
|
|
27 |
|
|
use ieee.std_logic_1164.all;
|
28 |
|
|
use ieee.std_logic_arith.all;
|
29 |
|
|
use ieee.std_logic_unsigned.all;
|
30 |
|
|
|
31 |
|
|
use work.powerGrid.all;
|
32 |
39 |
jguarin200 |
use work.scanPack.all;
|
33 |
14 |
jguarin200 |
|
34 |
|
|
entity dComparisonCell is
|
35 |
39 |
jguarin200 |
generic (
|
36 |
|
|
W1 : integer := 32; -- operands Width ( reference V.D and column V.D)
|
37 |
|
|
IDW : integer := 2; -- Column Sphere ID width. 1 = 2 columns max, 2= 4 colums max... and so on.
|
38 |
|
|
C : integer := 0 -- Column Id
|
39 |
14 |
jguarin200 |
);
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
port (
|
43 |
39 |
jguarin200 |
-- The usual control signals.
|
44 |
|
|
clk, rst, pipeOn : in std_logic;
|
45 |
|
|
|
46 |
|
|
-- Scan signals (not so usual)
|
47 |
|
|
-- scanOut disables the main comparison functionality of the cell and turns it into a scan shift.
|
48 |
|
|
-- when scanOut is set (1), scan shift mode is on, scanCommand commands what scan action is taking place,
|
49 |
|
|
-- when scanCommand is set (1), a scan load action is taking place, when is not set (0) a scan shift is taking place.
|
50 |
|
|
scanOut, scanCommand : in std_logic;
|
51 |
|
|
|
52 |
|
|
-- Reference intersection signal.
|
53 |
|
|
intd : in std_logic;
|
54 |
|
|
intq : out std_logic;
|
55 |
|
|
|
56 |
|
|
cIdd : in std_logic_vector (IDW - 1 downto 0); -- This is the reference column identification input.
|
57 |
|
|
cIdq : out std_logic_vector (IDW - 1 downto 0); -- This is the sphere identification output.
|
58 |
|
|
|
59 |
|
|
refk : in std_logic_vector (W1 - 1 downto 0); -- This is the columns sphere constant
|
60 |
|
|
colk : in std_logic_vector (W1 - 1 downto 0); -- This is the reference sphere constant
|
61 |
|
|
selk : in std_logic_vector (W1 - 1 downto 0); -- This is the selected sphere constant
|
62 |
|
|
|
63 |
|
|
refvd : in std_logic_vector (W1 - 1 downto 0); -- This is the projection incoming from the previous cell.
|
64 |
|
|
colvd : in std_logic_vector (W1 - 1 downto 0); -- This is the projection of the sphere position over the ray traced vector, a.k.a. V.D! .
|
65 |
|
|
selvd : out std_logic_vector (W1 - 1 downto 0) -- This is the smallest value between refvd and colvd.
|
66 |
21 |
jguarin200 |
);
|
67 |
14 |
jguarin200 |
|
68 |
|
|
end entity;
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
architecture rtl of dComparisonCell is
|
72 |
|
|
|
73 |
39 |
jguarin200 |
signal sena : std_logic; -- This signal enables the scan ff.
|
74 |
|
|
signal ssl32 : std_logic; -- This signal indicates if refvd is less than colvd
|
75 |
|
|
signal qdist : std_logic_vector (IDW+W1 downto 0);
|
76 |
21 |
jguarin200 |
|
77 |
14 |
jguarin200 |
begin
|
78 |
|
|
|
79 |
21 |
jguarin200 |
-- A less than B comparison, check if colvd is less than refvd, meaning the act V.D less than actual min V.D
|
80 |
39 |
jguarin200 |
cl32: sl32
|
81 |
|
|
port map (
|
82 |
|
|
dataa => colvd,
|
83 |
|
|
datab => refvd,
|
84 |
|
|
AlB => ssl32
|
85 |
|
|
);
|
86 |
14 |
jguarin200 |
|
87 |
32 |
jguarin200 |
-- A flip flop with 2 to 1 mux.Selects between the smallest vd.
|
88 |
39 |
jguarin200 |
selectorVD: scanFF generic map ( W => W1)
|
89 |
|
|
port map (
|
90 |
|
|
clk => clk,
|
91 |
|
|
rst => rst,
|
92 |
|
|
ena => pipeOn or scanOut,
|
93 |
|
|
sel => (ssl32 and not(scanOut))or(scanCommand and scanOut),
|
94 |
|
|
d0 => refvd,
|
95 |
|
|
d1 => colvd,
|
96 |
|
|
q => selvd
|
97 |
|
|
);
|
98 |
|
|
-- Another flip flip with 2 to 1 mux. Selects the column id the intersection signal of the smallest vd and the selected K.
|
99 |
|
|
selectorID: scanFF
|
100 |
|
|
generic map (
|
101 |
|
|
W = W1+IDW+1
|
102 |
|
|
)
|
103 |
|
|
port map (
|
104 |
|
|
clk => clk,
|
105 |
|
|
rst => rst,
|
106 |
|
|
ena => pipeOn or scanOut,
|
107 |
|
|
sel => (ssl32 and not(scanOut))or(scanCommand and scanOut),
|
108 |
|
|
d0 => refk&cIdd&intd,
|
109 |
|
|
d1 => colk&conv_std_logic_vector(C,IDW)&ssl32,
|
110 |
|
|
q => qdist
|
111 |
|
|
);
|
112 |
32 |
jguarin200 |
|
113 |
39 |
jguarin200 |
selk <= qdist(IDW + W1 downto IDW+1);
|
114 |
|
|
cIdq <= qdist(IDW downto 1);
|
115 |
32 |
jguarin200 |
intq <= qdist(0);
|
116 |
|
|
|
117 |
14 |
jguarin200 |
|
118 |
|
|
end rtl;
|