1 |
150 |
jguarin200 |
--! @file memblock.vhd
|
2 |
152 |
jguarin200 |
--! @brief Bloque de memoria.
|
3 |
128 |
jguarin200 |
--! @author Julián Andrés Guarín Reyes
|
4 |
|
|
--------------------------------------------------------------
|
5 |
|
|
-- RAYTRAC
|
6 |
|
|
-- Author Julian Andres Guarin
|
7 |
|
|
-- memblock.vhd
|
8 |
|
|
-- 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 |
151 |
jguarin200 |
use work.arithpack.all;
|
26 |
129 |
jguarin200 |
|
27 |
128 |
jguarin200 |
entity memblock is
|
28 |
|
|
generic (
|
29 |
129 |
jguarin200 |
|
30 |
|
|
blocksize : integer := 512;
|
31 |
152 |
jguarin200 |
|
32 |
129 |
jguarin200 |
external_writeable_blocks : integer := 12;
|
33 |
|
|
external_readable_blocks : integer := 8;
|
34 |
|
|
external_readable_widthad : integer := 3;
|
35 |
|
|
external_writeable_widthad : integer := 4
|
36 |
128 |
jguarin200 |
);
|
37 |
|
|
port (
|
38 |
|
|
|
39 |
147 |
jguarin200 |
clk,rst,dpfifo_rd,normfifo_rd,dpfifo_wr,normfifo_wr : in std_logic;
|
40 |
150 |
jguarin200 |
instrfifo_rd : in std_logic;
|
41 |
|
|
resultfifo_wr: in std_logic_vector(external_readable_blocks-1 downto 0);
|
42 |
147 |
jguarin200 |
instrfifo_empty: out std_logic;
|
43 |
138 |
jguarin200 |
ext_rd,ext_wr: in std_logic;
|
44 |
129 |
jguarin200 |
ext_wr_add : in std_logic_vector(external_writeable_widthad+widthadmemblock-1 downto 0);
|
45 |
138 |
jguarin200 |
ext_rd_add : in std_logic_vector(external_readable_widthad-1 downto 0);
|
46 |
152 |
jguarin200 |
ext_d: in std_logic_vector(floatwidth-1 downto 0);
|
47 |
150 |
jguarin200 |
resultfifo_full : out std_logic_vector(3 downto 0);
|
48 |
152 |
jguarin200 |
int_d : in std_logic_vector(external_readable_blocks*floatwidth-1 downto 0);
|
49 |
|
|
|
50 |
|
|
--!Python
|
51 |
|
|
ext_q,instr fifo_q : out std_logic_vector(floatwidth-1 downto 0);
|
52 |
|
|
int_q : out std_logic_vector(external_writeable_blocks*floatwidth-1 downto 0);
|
53 |
130 |
jguarin200 |
int_rd_add : in std_logic_vector(2*widthadmemblock-1 downto 0);
|
54 |
152 |
jguarin200 |
dpfifo_d : in std_logic_vector(floatwidth*2-1 downto 0);
|
55 |
|
|
normfifo_d : in std_logic_vector(floatwidth*3-1 downto 0);
|
56 |
|
|
dpfifo_q : out std_logic_vector(floatwidth*2-1 downto 0);
|
57 |
|
|
normfifo_q : out std_logic_vector(floatwidth*3-1 downto 0)
|
58 |
128 |
jguarin200 |
);
|
59 |
|
|
end memblock;
|
60 |
|
|
|
61 |
|
|
architecture memblock_arch of memblock is
|
62 |
|
|
|
63 |
129 |
jguarin200 |
|
64 |
|
|
|
65 |
147 |
jguarin200 |
|
66 |
151 |
jguarin200 |
|
67 |
152 |
jguarin200 |
--!TBXSTART:MEMBLOCK_EXTERNAL_WRITE
|
68 |
|
|
signal s0ext_wr_add_one_hot : std_logic_vector(external_writeable_blocks-1+1 downto 0); --! La señal extra es para la escritura de la cola de instrucciones.
|
69 |
129 |
jguarin200 |
signal s0ext_wr_add : std_logic_vector(external_writeable_widthad+widthadmemblock-1 downto 0);
|
70 |
152 |
jguarin200 |
signal s0ext_wr : std_logic;
|
71 |
|
|
signal s0ext_d : std_logic_vector(floatwidth-1 downto 0);
|
72 |
|
|
--!TBXEND
|
73 |
|
|
|
74 |
|
|
--!TBXSTART:MEMBLOCK_EXTERNAL_READ
|
75 |
130 |
jguarin200 |
signal s0ext_rd_add : std_logic_vector(external_readable_widthad-1 downto 0);
|
76 |
152 |
jguarin200 |
signal s0ext_rd : std_logic;
|
77 |
|
|
signal s0ext_rd_ack : std_logic_vector(external_readable_blocks-1 downto 0);
|
78 |
|
|
signal s0ext_q : vectorblock08;
|
79 |
|
|
--!TBXEND
|
80 |
|
|
|
81 |
|
|
--!TBXSTART:MEMBLOCK_INTERNAL_READ
|
82 |
129 |
jguarin200 |
signal s0int_rd_add : std_logic_vector(widthadmemblock-1 downto 0);
|
83 |
152 |
jguarin200 |
signal sint_rd_add : vectorblockadd02;
|
84 |
138 |
jguarin200 |
signal s1int_q : vectorblock12;
|
85 |
152 |
jguarin200 |
--!TBXEND
|
86 |
|
|
|
87 |
|
|
--!TBXSTART:MEMBLOCK_INTERNAL_WRITE
|
88 |
|
|
signal sint_d : vectorblock08;
|
89 |
150 |
jguarin200 |
signal sresultfifo_full : std_logic_vector(7 downto 0);
|
90 |
152 |
jguarin200 |
--!TBXEND
|
91 |
130 |
jguarin200 |
|
92 |
128 |
jguarin200 |
begin
|
93 |
|
|
|
94 |
152 |
jguarin200 |
--! Cola interna de producto cccccpunto, ubicada entre el pipe line aritméco.
|
95 |
140 |
jguarin200 |
q0q1 : scfifo --! Debe ir registrada la salida.
|
96 |
147 |
jguarin200 |
generic map (
|
97 |
|
|
add_ram_output_register => "OFF",
|
98 |
|
|
allow_wrcycle_when_full => "OFF",
|
99 |
|
|
intended_device_family => "CycloneIII",
|
100 |
|
|
lpm_hint => "RAM_BLOCK_TYPE=M9K",
|
101 |
|
|
almost_full_value => 8,
|
102 |
|
|
lpm_numwords => 8,
|
103 |
|
|
lpm_showahead => "ON",
|
104 |
|
|
lpm_type => "SCIFIFO",
|
105 |
|
|
lpm_width => 64,
|
106 |
|
|
lpm_widthu => 3,
|
107 |
|
|
overflow_checking => "ON",
|
108 |
|
|
underflow_checking => "ON",
|
109 |
|
|
use_eab => "ON"
|
110 |
|
|
)
|
111 |
|
|
port map (
|
112 |
|
|
rdreq => dpfifo_rd,
|
113 |
|
|
aclr => '0',
|
114 |
|
|
empty => open,
|
115 |
|
|
clock => clk,
|
116 |
|
|
q => dpfifo_q,
|
117 |
|
|
wrreq => dpfifo_wr,
|
118 |
|
|
data => dpfifo_d
|
119 |
|
|
);
|
120 |
140 |
jguarin200 |
|
121 |
152 |
jguarin200 |
--! Cola interna de normalización de vectores, ubicada entre el pipeline aritmético
|
122 |
140 |
jguarin200 |
qxqyqz : scfifo
|
123 |
147 |
jguarin200 |
generic map (
|
124 |
|
|
add_ram_output_register => "OFF",
|
125 |
|
|
allow_wrcycle_when_full => "OFF",
|
126 |
|
|
intended_device_family => "Cyclone III",
|
127 |
|
|
lpm_hint => "RAM_BLOCK_TYPE=M9K",
|
128 |
|
|
almost_full_value => 32,
|
129 |
|
|
lpm_numwords => 32,
|
130 |
|
|
lpm_showahead => "ON",
|
131 |
|
|
lpm_type => "SCFIFO",
|
132 |
|
|
lpm_width => 96,
|
133 |
|
|
lpm_widthu => 5,
|
134 |
|
|
overflow_checking => "ON",
|
135 |
|
|
underflow_checking => "ON",
|
136 |
|
|
use_eab => "ON"
|
137 |
|
|
)
|
138 |
|
|
port map (
|
139 |
|
|
rdreq => normfifo_rd,
|
140 |
|
|
aclr => '0',
|
141 |
|
|
empty => open,
|
142 |
|
|
clock => clk,
|
143 |
|
|
q => normfifo_q,
|
144 |
|
|
wrreq => normfifo_wr,
|
145 |
|
|
data => normfifo_d,
|
146 |
|
|
almost_full => open,
|
147 |
|
|
full => open
|
148 |
|
|
);
|
149 |
140 |
jguarin200 |
|
150 |
|
|
--! Cola de instrucciones
|
151 |
|
|
qi : scfifo
|
152 |
147 |
jguarin200 |
generic map (
|
153 |
|
|
add_ram_output_register => "OFF",
|
154 |
|
|
allow_wrcycle_when_full => "OFF",
|
155 |
|
|
intended_device_family => "Cyclone III",
|
156 |
|
|
lpm_hint => "RAM_BLOCK_TYPE=M9K",
|
157 |
|
|
almost_full_value => 32,
|
158 |
|
|
lpm_numwords => 32,
|
159 |
|
|
lpm_showahead => "OFF",
|
160 |
|
|
lpm_type => "SCIFIFO",
|
161 |
|
|
lpm_width => 32,
|
162 |
|
|
lpm_widthu => 5,
|
163 |
|
|
overflow_checking => "ON",
|
164 |
|
|
underflow_checking => "ON",
|
165 |
|
|
use_eab => "ON"
|
166 |
|
|
)
|
167 |
|
|
port map (
|
168 |
|
|
rdreq => instrfifo_rd,
|
169 |
|
|
aclr => '0',
|
170 |
|
|
empty => instrfifo_empty,
|
171 |
|
|
clock => clk,
|
172 |
|
|
q => instrfifo_q,
|
173 |
150 |
jguarin200 |
wrreq => s0ext_wr_add_one_hot(12),
|
174 |
|
|
data => s0ext_d,
|
175 |
147 |
jguarin200 |
almost_full => open
|
176 |
|
|
);
|
177 |
128 |
jguarin200 |
|
178 |
140 |
jguarin200 |
--! Conectar los registros de lectura interna del bloque de operandos a los arreglos > abstracció:n de código, no influye en la sintesis del circuito.
|
179 |
130 |
jguarin200 |
sint_rd_add (0)<= int_rd_add(widthadmemblock-1 downto 0);
|
180 |
|
|
sint_rd_add (1)<= int_rd_add(2*widthadmemblock-1 downto widthadmemblock);
|
181 |
|
|
|
182 |
147 |
jguarin200 |
--! Instanciación de la cola de resultados de salida.
|
183 |
|
|
operands_blocks:
|
184 |
|
|
for i in 11 downto 0 generate
|
185 |
152 |
jguarin200 |
int_q((i+1)*floatwidth-1 downto floatwidth*i) <= s1int_q(i);
|
186 |
147 |
jguarin200 |
operandsblock : altsyncram
|
187 |
|
|
generic map (
|
188 |
|
|
address_aclr_b => "NONE",
|
189 |
|
|
address_reg_b => "CLOCK0",
|
190 |
|
|
clock_enable_input_a => "BYPASS",
|
191 |
|
|
clock_enable_input_b => "BYPASS",
|
192 |
|
|
clock_enable_output_b => "BYPASS",
|
193 |
|
|
intended_device_family => "Cyclone III",
|
194 |
|
|
lpm_type => "altsyncram",
|
195 |
|
|
numwords_a => 2**widthadmemblock,
|
196 |
|
|
numwords_b => 2**widthadmemblock,
|
197 |
|
|
operation_mode => "DUAL_PORT",
|
198 |
|
|
outdata_aclr_b => "NONE",
|
199 |
|
|
outdata_reg_b => "CLOCK0",
|
200 |
|
|
power_up_uninitialized => "FALSE",
|
201 |
|
|
ram_block_type => "M9K",
|
202 |
|
|
rdcontrol_reg_b => "CLOCK0",
|
203 |
|
|
read_during_write_mode_mixed_ports => "OLD_DATA",
|
204 |
|
|
widthad_a => widthadmemblock,
|
205 |
|
|
widthad_b => widthadmemblock,
|
206 |
152 |
jguarin200 |
width_a => floatwidth,
|
207 |
|
|
width_b => floatwidth,
|
208 |
147 |
jguarin200 |
width_byteena_a => 1
|
209 |
|
|
)
|
210 |
|
|
port map (
|
211 |
|
|
wren_a => s0ext_wr_add_one_hot(i),
|
212 |
|
|
clock0 => clk,
|
213 |
|
|
address_a => s0ext_wr_add(widthadmemblock-1 downto 0),
|
214 |
|
|
address_b => sint_rd_add((i/3) mod 2),
|
215 |
|
|
rden_b => '1',
|
216 |
|
|
q_b => s1int_q(i),
|
217 |
|
|
data_a => s0ext_d
|
218 |
|
|
);
|
219 |
|
|
end generate operands_blocks;
|
220 |
|
|
|
221 |
140 |
jguarin200 |
--! Instanciación de la cola de resultados.
|
222 |
150 |
jguarin200 |
resultfifo_full(3) <= sresultfifo_full(7) or sresultfifo_full(6) or sresultfifo_full(5);
|
223 |
|
|
resultfifo_full(2) <= sresultfifo_full(4) or sresultfifo_full(2);
|
224 |
|
|
resultfifo_full(1) <= sresultfifo_full(3) or sresultfifo_full(2) or sresultfifo_full(1);
|
225 |
|
|
resultfifo_full(0) <= sresultfifo_full(0);
|
226 |
130 |
jguarin200 |
results_blocks:
|
227 |
|
|
for i in 7 downto 0 generate
|
228 |
152 |
jguarin200 |
sint_d(i) <= int_d((i+1)*floatwidth-1 downto i*floatwidth);
|
229 |
138 |
jguarin200 |
resultsfifo : scfifo
|
230 |
147 |
jguarin200 |
generic map (
|
231 |
|
|
add_ram_output_register => "OFF",
|
232 |
|
|
almost_full_value => 480,
|
233 |
|
|
allow_wrcycle_when_full => "OFF",
|
234 |
|
|
intended_device_family => "Cyclone III",
|
235 |
|
|
lpm_hint => "RAM_BLOCK_TYPE=M9K",
|
236 |
|
|
lpm_numwords => 512,
|
237 |
|
|
lpm_showahead => "ON",
|
238 |
|
|
lpm_type => "SCIFIFO",
|
239 |
|
|
lpm_width => 32,
|
240 |
|
|
lpm_widthu => 9,
|
241 |
|
|
overflow_checking => "ON",
|
242 |
|
|
underflow_checking => "ON",
|
243 |
|
|
use_eab => "ON"
|
244 |
|
|
)
|
245 |
|
|
port map (
|
246 |
|
|
rdreq => s0ext_rd_ack(i),
|
247 |
|
|
aclr => '0',
|
248 |
150 |
jguarin200 |
empty => open,
|
249 |
147 |
jguarin200 |
clock => clk,
|
250 |
|
|
q => s0ext_q(i),
|
251 |
150 |
jguarin200 |
wrreq => resultfifo_wr(i),
|
252 |
147 |
jguarin200 |
data => sint_d(i),
|
253 |
150 |
jguarin200 |
almost_full => sresultfifo_full(i),
|
254 |
147 |
jguarin200 |
full => open
|
255 |
|
|
);
|
256 |
130 |
jguarin200 |
end generate results_blocks;
|
257 |
|
|
|
258 |
140 |
jguarin200 |
--! Escritura en registros de operandos de entrada.
|
259 |
147 |
jguarin200 |
operands_block_proc: process (clk,rst)
|
260 |
129 |
jguarin200 |
begin
|
261 |
147 |
jguarin200 |
if rst=rstMasterValue then
|
262 |
|
|
s0ext_wr_add <= (others => '0');
|
263 |
|
|
s0ext_wr <= '0';
|
264 |
|
|
s0ext_d <= (others => '0');
|
265 |
|
|
elsif clk'event and clk='1' then
|
266 |
|
|
--! Registro de entrada
|
267 |
|
|
s0ext_wr_add <= ext_wr_add;
|
268 |
|
|
s0ext_wr <= ext_wr;
|
269 |
|
|
s0ext_d <= ext_d;
|
270 |
129 |
jguarin200 |
end if;
|
271 |
|
|
end process;
|
272 |
140 |
jguarin200 |
|
273 |
|
|
--! Decodificación de señal escritura x bloque de memoria, selecciona la memoria en la que se va a escribir a partir de la dirección de entrada.
|
274 |
138 |
jguarin200 |
operands_block_comb: process (s0ext_wr_add,s0ext_wr)
|
275 |
130 |
jguarin200 |
begin
|
276 |
138 |
jguarin200 |
|
277 |
140 |
jguarin200 |
--! Etapa 0: Decodificacion de las señ:ales de escritura.Revisar el capitulo de bloques de memoria para chequear como está el pool de direcciones por bloques de vectores.
|
278 |
141 |
jguarin200 |
--! Las direcciones de bloque 3,7,11,15 corresponden a la cola de instrucciones.
|
279 |
138 |
jguarin200 |
case s0ext_wr_add(external_writeable_widthad+widthadmemblock-1 downto widthadmemblock) is
|
280 |
140 |
jguarin200 |
when x"0" => s0ext_wr_add_one_hot <= '0'&x"00"&"000"&s0ext_wr;
|
281 |
|
|
when x"1" => s0ext_wr_add_one_hot <= '0'&x"00"&"00"&s0ext_wr&'0';
|
282 |
|
|
when x"2" => s0ext_wr_add_one_hot <= '0'&x"00"&'0'&s0ext_wr&"00";
|
283 |
|
|
when x"4" => s0ext_wr_add_one_hot <= '0'&x"00"&s0ext_wr&"000";
|
284 |
|
|
when x"5" => s0ext_wr_add_one_hot <= '0'&x"0"&"000"&s0ext_wr&x"0";
|
285 |
|
|
when x"6" => s0ext_wr_add_one_hot <= '0'&x"0"&"00"&s0ext_wr&'0'&x"0";
|
286 |
|
|
when x"8" => s0ext_wr_add_one_hot <= '0'&x"0"&'0'&s0ext_wr&"00"&x"0";
|
287 |
|
|
when x"9" => s0ext_wr_add_one_hot <= '0'&x"0"&s0ext_wr&"000"&x"0";
|
288 |
|
|
when x"A" => s0ext_wr_add_one_hot <= '0'&"000"&s0ext_wr&x"00";
|
289 |
|
|
when x"C" => s0ext_wr_add_one_hot <= '0'&"00"&s0ext_wr&'0'&x"00";
|
290 |
|
|
when x"D" => s0ext_wr_add_one_hot <= '0'&'0'&s0ext_wr&"00"&x"00";
|
291 |
|
|
when x"E" => s0ext_wr_add_one_hot <= '0'&s0ext_wr&"000"&x"00";
|
292 |
150 |
jguarin200 |
when others => s0ext_wr_add_one_hot <= s0ext_wr&x"000";
|
293 |
138 |
jguarin200 |
end case;
|
294 |
|
|
|
295 |
|
|
end process;
|
296 |
140 |
jguarin200 |
|
297 |
|
|
--! Decodificación para seleccionar que cola de resultados se conectar´ a la salida del RayTrac.
|
298 |
147 |
jguarin200 |
results_block_proc: process(clk,rst)
|
299 |
138 |
jguarin200 |
begin
|
300 |
147 |
jguarin200 |
if rst=rstMasterValue then
|
301 |
|
|
s0ext_rd_add <= (others => '0');
|
302 |
|
|
s0ext_rd <= '0';
|
303 |
|
|
elsif clk'event and clk='1' then
|
304 |
130 |
jguarin200 |
--!Registrar entrada
|
305 |
138 |
jguarin200 |
s0ext_rd_add <= ext_rd_add;
|
306 |
|
|
s0ext_rd <= ext_rd;
|
307 |
|
|
--!Etapa 0: Decodificar la cola que se va a mover (rdack! fifo showahead mode) y por ende leer ese dato.
|
308 |
|
|
case '0'&s0ext_rd_add is
|
309 |
|
|
when x"0" => ext_q <= s0ext_q(0);
|
310 |
|
|
when x"1" => ext_q <= s0ext_q(1);
|
311 |
|
|
when x"2" => ext_q <= s0ext_q(2);
|
312 |
|
|
when x"3" => ext_q <= s0ext_q(3);
|
313 |
|
|
when x"4" => ext_q <= s0ext_q(4);
|
314 |
|
|
when x"5" => ext_q <= s0ext_q(5);
|
315 |
|
|
when x"6" => ext_q <= s0ext_q(6);
|
316 |
|
|
when others => ext_q <= s0ext_q(7);
|
317 |
130 |
jguarin200 |
end case;
|
318 |
|
|
end if;
|
319 |
|
|
end process;
|
320 |
140 |
jguarin200 |
|
321 |
|
|
--! rdack decoder para las colas de resultados de salida.
|
322 |
138 |
jguarin200 |
results_block_proc_combinatorial_stage: process(s0ext_rd,s0ext_rd_add)
|
323 |
|
|
begin
|
324 |
|
|
case '0'&s0ext_rd_add is
|
325 |
|
|
when x"0" => s0ext_rd_ack <= x"0"&"000"&s0ext_rd;
|
326 |
|
|
when x"1" => s0ext_rd_ack <= x"0"&"00"&s0ext_rd&'0';
|
327 |
|
|
when x"2" => s0ext_rd_ack <= x"0"&"0"&s0ext_rd&"00";
|
328 |
|
|
when x"3" => s0ext_rd_ack <= x"0"&s0ext_rd&"000";
|
329 |
|
|
when x"4" => s0ext_rd_ack <= "000"&s0ext_rd&x"0";
|
330 |
|
|
when x"5" => s0ext_rd_ack <= "00"&s0ext_rd&'0'&x"0";
|
331 |
|
|
when x"6" => s0ext_rd_ack <= "0"&s0ext_rd&"00"&x"0";
|
332 |
|
|
when others => s0ext_rd_ack <= s0ext_rd&"000"&x"0";
|
333 |
|
|
end case;
|
334 |
|
|
end process;
|
335 |
128 |
jguarin200 |
end memblock_arch;
|
336 |
|
|
|