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

Subversion Repositories raytrac

[/] [raytrac/] [branches/] [fp/] [memblock.vhd] - Blame information for rev 196

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

Line No. Rev Author Line
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_readable_widthad       : integer := 3;
33
                external_writeable_widthad      : integer := 4
34 128 jguarin200
        );
35
        port (
36
 
37 147 jguarin200
                clk,rst,dpfifo_rd,normfifo_rd,dpfifo_wr,normfifo_wr : in std_logic;
38 150 jguarin200
                instrfifo_rd : in std_logic;
39 158 jguarin200
                resultfifo_wr: in std_logic_vector(8-1 downto 0);
40 147 jguarin200
                instrfifo_empty: out std_logic;
41 138 jguarin200
                ext_rd,ext_wr: in std_logic;
42 158 jguarin200
                ext_wr_add : in std_logic_vector(4+widthadmemblock-1 downto 0);
43 181 jguarin200
                ext_rd_add : in std_logic_vector(3 downto 0);
44 152 jguarin200
                ext_d: in std_logic_vector(floatwidth-1 downto 0);
45 150 jguarin200
                resultfifo_full  : out std_logic_vector(3 downto 0);
46 158 jguarin200
                int_d : in vectorblock08;
47 152 jguarin200
 
48 181 jguarin200
                status_register : in std_logic_vector(3 downto 0);
49
 
50 153 jguarin200
                ext_q,instrfifo_q : out std_logic_vector(floatwidth-1 downto 0);
51 158 jguarin200
                int_q : out vectorblock12;
52 130 jguarin200
                int_rd_add : in std_logic_vector(2*widthadmemblock-1 downto 0);
53 152 jguarin200
                dpfifo_d : in std_logic_vector(floatwidth*2-1 downto 0);
54
                normfifo_d : in std_logic_vector(floatwidth*3-1 downto 0);
55
                dpfifo_q : out std_logic_vector(floatwidth*2-1 downto 0);
56
                normfifo_q : out std_logic_vector(floatwidth*3-1 downto 0)
57 128 jguarin200
        );
58 153 jguarin200
end entity;
59 128 jguarin200
 
60
architecture memblock_arch of memblock is
61
 
62 129 jguarin200
 
63
 
64 181 jguarin200
 
65 147 jguarin200
 
66 161 jguarin200
        --!TXBXSTART:MEMBLOCK_EXTERNAL_WRITE
67 158 jguarin200
        signal s0ext_wr_add_one_hot : std_logic_vector(12-1+1 downto 0); --! La se&ntilde;al extra es para la escritura de la cola de instrucciones.
68
        signal s0ext_wr_add                     : std_logic_vector(4+widthadmemblock-1 downto 0);
69 152 jguarin200
        signal s0ext_wr                         : std_logic;
70
        signal s0ext_d                          : std_logic_vector(floatwidth-1 downto 0);
71
        --!TBXEND
72 157 jguarin200
        --! Se&ntilde;al de soporte
73
        signal s0ext_wr_add_choice      : std_logic_vector(3 downto 0);
74 152 jguarin200
 
75 160 jguarin200
        --!TXBXSTART:MEMBLOCK_EXTERNAL_READ
76 181 jguarin200
        signal s0status_register        : std_logic_vector(7 downto 0);
77
        signal s0ext_rd_add                     : std_logic_vector(3 downto 0);
78 152 jguarin200
        signal s0ext_rd                         : std_logic;
79 158 jguarin200
        signal s0ext_rd_ack                     : std_logic_vector(8-1 downto 0);
80 152 jguarin200
        signal s0ext_q                          : vectorblock08;
81
        --!TBXEND
82
 
83 157 jguarin200
 
84 152 jguarin200
        --!TBXSTART:MEMBLOCK_INTERNAL_READ
85
        signal sint_rd_add                      : vectorblockadd02;
86 138 jguarin200
        signal s1int_q                          : vectorblock12;
87 152 jguarin200
        --!TBXEND
88
 
89 160 jguarin200
        --!TXBXSTART:MEMBLOCK_INTERNAL_WRITE
90 152 jguarin200
        signal sint_d                           : vectorblock08;
91 150 jguarin200
        signal sresultfifo_full         : std_logic_vector(7 downto 0);
92 152 jguarin200
        --!TBXEND
93 130 jguarin200
 
94 128 jguarin200
begin
95 181 jguarin200
 
96
 
97
 
98 128 jguarin200
 
99 181 jguarin200
 
100 174 jguarin200
        --! Colas internas de producto punto, ubicada en el pipe line aritm&eacute;co. Paralelo a los sumadores a0 y a2.  
101 140 jguarin200
        q0q1 : scfifo --! Debe ir registrada la salida.
102 147 jguarin200
        generic map (
103
                add_ram_output_register => "OFF",
104 159 jguarin200
                allow_rwcycle_when_full => "OFF",
105 147 jguarin200
                intended_device_family  => "CycloneIII",
106 190 jguarin200
                lpm_hint                                => "MAXIMUM_DEPTH=8",
107 147 jguarin200
                almost_full_value               => 8,
108
                lpm_numwords                    => 8,
109
                lpm_showahead                   => "ON",
110
                lpm_type                                => "SCIFIFO",
111
                lpm_width                               => 64,
112
                lpm_widthu                              => 3,
113
                overflow_checking               => "ON",
114
                underflow_checking              => "ON",
115 190 jguarin200
                use_eab                                 => "OFF"
116 147 jguarin200
        )
117
        port    map (
118
                rdreq           => dpfifo_rd,
119
                aclr            => '0',
120
                empty           => open,
121
                clock           => clk,
122
                q                       => dpfifo_q,
123
                wrreq           => dpfifo_wr,
124
                data            => dpfifo_d
125
        );
126 140 jguarin200
 
127 152 jguarin200
        --! Cola interna de normalizaci&oacute;n de vectores, ubicada entre el pipeline aritm&eacute;tico
128 140 jguarin200
        qxqyqz : scfifo
129 147 jguarin200
        generic map (
130
                add_ram_output_register => "OFF",
131 159 jguarin200
                allow_rwcycle_when_full => "OFF",
132 147 jguarin200
                intended_device_family  => "Cyclone III",
133
                lpm_hint                => "RAM_BLOCK_TYPE=M9K",
134
                almost_full_value               => 32,
135
                lpm_numwords                    => 32,
136 189 jguarin200
                lpm_showahead                   => "OFF",
137 147 jguarin200
                lpm_type                                => "SCFIFO",
138
                lpm_width                               => 96,
139
                lpm_widthu                              => 5,
140
                overflow_checking               => "ON",
141
                underflow_checking              => "ON",
142
                use_eab                                 => "ON"
143
        )
144
        port    map (
145
                rdreq           => normfifo_rd,
146
                aclr            => '0',
147
                empty           => open,
148
                clock           => clk,
149
                q                       => normfifo_q,
150
                wrreq           => normfifo_wr,
151
                data            => normfifo_d,
152
                almost_full => open,
153
                full            => open
154
        );
155 140 jguarin200
 
156
        --! Cola de instrucciones 
157
        qi : scfifo
158 147 jguarin200
        generic map (
159
                add_ram_output_register => "OFF",
160 159 jguarin200
                allow_rwcycle_when_full => "OFF",
161 147 jguarin200
                intended_device_family  => "Cyclone III",
162
                lpm_hint                                => "RAM_BLOCK_TYPE=M9K",
163 191 jguarin200
                almost_full_value               => 16,
164
                lpm_numwords                    => 16,
165 160 jguarin200
                lpm_showahead                   => "ON",
166 147 jguarin200
                lpm_type                                => "SCIFIFO",
167
                lpm_width                               => 32,
168 191 jguarin200
                lpm_widthu                              => 4,
169 147 jguarin200
                overflow_checking               => "ON",
170
                underflow_checking              => "ON",
171 191 jguarin200
                use_eab                                 => "OFF"
172 147 jguarin200
        )
173
        port    map (
174
                rdreq           => instrfifo_rd,
175
                aclr            => '0',
176
                empty           => instrfifo_empty,
177
                clock           => clk,
178
                q                       => instrfifo_q,
179 150 jguarin200
                wrreq           => s0ext_wr_add_one_hot(12),
180
                data            => s0ext_d,
181 147 jguarin200
                almost_full => open
182
        );
183 128 jguarin200
 
184 140 jguarin200
        --! Conectar los registros de lectura interna del bloque de operandos a los arreglos > abstracci&oacute:n de c&oacute;digo, no influye en la sintesis del circuito.
185 189 jguarin200
        sint_rd_add (0)<= int_rd_add(widthadmemblock-1-memoryreduction downto 0);
186
        sint_rd_add (1)<= int_rd_add(2*widthadmemblock-1-memoryreduction downto widthadmemblock);
187 130 jguarin200
 
188 147 jguarin200
        --! Instanciaci&oacute;n de la cola de resultados de salida.
189 158 jguarin200
        int_q <= s1int_q;
190 147 jguarin200
        operands_blocks:
191
        for i in 11 downto 0 generate
192 158 jguarin200
                --!int_q((i+1)*floatwidth-1 downto floatwidth*i) <= s1int_q(i);
193 147 jguarin200
                operandsblock : altsyncram
194
                generic map (
195
                        address_aclr_b                                          => "NONE",
196
                        address_reg_b                                           => "CLOCK0",
197
                        clock_enable_input_a                            => "BYPASS",
198
                        clock_enable_input_b                            => "BYPASS",
199
                        clock_enable_output_b                           => "BYPASS",
200
                        intended_device_family                          => "Cyclone III",
201
                        lpm_type                                                        => "altsyncram",
202 189 jguarin200
                        numwords_a                                                      => 2**(widthadmemblock-memoryreduction),
203
                        numwords_b                                                      => 2**(widthadmemblock-memoryreduction),
204 147 jguarin200
                        operation_mode                                          => "DUAL_PORT",
205
                        outdata_aclr_b                                          => "NONE",
206
                        outdata_reg_b                                           => "CLOCK0",
207
                        power_up_uninitialized                          => "FALSE",
208
                        ram_block_type                                          => "M9K",
209
                        rdcontrol_reg_b                                         => "CLOCK0",
210
                        read_during_write_mode_mixed_ports      => "OLD_DATA",
211 189 jguarin200
                        widthad_a                                                       => widthadmemblock-memoryreduction,
212
                        widthad_b                                                       => widthadmemblock-memoryreduction,
213 152 jguarin200
                        width_a                                                         => floatwidth,
214
                        width_b                                                         => floatwidth,
215 147 jguarin200
                        width_byteena_a                                         => 1
216
                )
217
                port map (
218
                        wren_a          => s0ext_wr_add_one_hot(i),
219
                        clock0          => clk,
220 189 jguarin200
                        address_a       => s0ext_wr_add(widthadmemblock-1-memoryreduction downto 0),
221 147 jguarin200
                        address_b       => sint_rd_add((i/3) mod 2),
222
                        rden_b          => '1',
223
                        q_b                     => s1int_q(i),
224
                        data_a          => s0ext_d
225
                );
226
        end generate operands_blocks;
227
 
228 140 jguarin200
        --! Instanciaci&oacute;n de la cola de resultados.
229 150 jguarin200
        resultfifo_full(3) <= sresultfifo_full(7) or sresultfifo_full(6) or sresultfifo_full(5);
230
        resultfifo_full(2) <= sresultfifo_full(4) or sresultfifo_full(2);
231
        resultfifo_full(1) <= sresultfifo_full(3) or sresultfifo_full(2) or sresultfifo_full(1);
232
        resultfifo_full(0) <= sresultfifo_full(0);
233 158 jguarin200
        sint_d <= int_d;
234 130 jguarin200
        results_blocks:
235
        for i in 7 downto 0 generate
236 138 jguarin200
                resultsfifo : scfifo
237 147 jguarin200
                generic map     (
238
                        add_ram_output_register => "OFF",
239 189 jguarin200
                        almost_full_value               => 224,
240 159 jguarin200
                        allow_rwcycle_when_full => "OFF",
241 147 jguarin200
                        intended_device_family  => "Cyclone III",
242
                        lpm_hint                                => "RAM_BLOCK_TYPE=M9K",
243 189 jguarin200
                        lpm_numwords                    => 256,
244 147 jguarin200
                        lpm_showahead                   => "ON",
245
                        lpm_type                                => "SCIFIFO",
246
                        lpm_width                               => 32,
247 189 jguarin200
                        lpm_widthu                              => 8,
248 147 jguarin200
                        overflow_checking               => "ON",
249
                        underflow_checking              => "ON",
250
                        use_eab                                 => "ON"
251
                )
252
                port    map (
253
                        rdreq           => s0ext_rd_ack(i),
254
                        aclr            => '0',
255 150 jguarin200
                        empty           => open,
256 147 jguarin200
                        clock           => clk,
257
                        q                       => s0ext_q(i),
258 150 jguarin200
                        wrreq           => resultfifo_wr(i),
259 147 jguarin200
                        data            => sint_d(i),
260 150 jguarin200
                        almost_full     => sresultfifo_full(i),
261 147 jguarin200
                        full            => open
262
                );
263 130 jguarin200
        end generate results_blocks;
264
 
265 140 jguarin200
        --! Escritura en registros de operandos de entrada.
266 147 jguarin200
        operands_block_proc: process (clk,rst)
267 129 jguarin200
        begin
268 147 jguarin200
                if rst=rstMasterValue then
269
                        s0ext_wr_add    <= (others => '0');
270
                        s0ext_wr                <= '0';
271
                        s0ext_d                 <= (others => '0');
272
                elsif clk'event and clk='1' then
273
                        --! Registro de entrada
274
                        s0ext_wr_add <= ext_wr_add;
275
                        s0ext_wr  <= ext_wr;
276
                        s0ext_d  <= ext_d;
277 129 jguarin200
                end if;
278
        end process;
279 140 jguarin200
 
280
        --! Decodificaci&oacute;n de se&ntilde;al escritura x bloque de memoria, selecciona la memoria en la que se va a escribir a partir de la direcci&oacute;n de entrada.
281 158 jguarin200
        s0ext_wr_add_choice <= s0ext_wr_add(4+widthadmemblock-1 downto widthadmemblock);
282 157 jguarin200
        operands_block_comb: process (s0ext_wr_add_choice,s0ext_wr)
283 130 jguarin200
        begin
284 138 jguarin200
 
285 140 jguarin200
                --! Etapa 0: Decodificacion de las se&ntilde:ales de escritura.Revisar el capitulo de bloques de memoria para chequear como est&aacute; el pool de direcciones por bloques de vectores.
286 141 jguarin200
                --! Las direcciones de bloque 3,7,11,15 corresponden a la cola de instrucciones.
287 157 jguarin200
                case s0ext_wr_add_choice is
288
                        when "0000" =>
289
                                s0ext_wr_add_one_hot <= '0'&x"00"&"000"&s0ext_wr;
290
                        when x"1" =>
291
                                s0ext_wr_add_one_hot <= '0'&x"00"&"00"&s0ext_wr&'0';
292
                        when x"2" =>
293
                                s0ext_wr_add_one_hot <= '0'&x"00"&'0'&s0ext_wr&"00";
294
                        when x"4" =>
295
                                s0ext_wr_add_one_hot <= '0'&x"00"&s0ext_wr&"000";
296
                        when x"5" =>
297
                                s0ext_wr_add_one_hot <= '0'&x"0"&"000"&s0ext_wr&x"0";
298
                        when x"6" =>
299
                                s0ext_wr_add_one_hot <= '0'&x"0"&"00"&s0ext_wr&'0'&x"0";
300
                        when x"8" =>
301
                                s0ext_wr_add_one_hot <= '0'&x"0"&'0'&s0ext_wr&"00"&x"0";
302
                        when x"9" =>
303
                                s0ext_wr_add_one_hot <= '0'&x"0"&s0ext_wr&"000"&x"0";
304
                        when x"A" =>
305
                                s0ext_wr_add_one_hot <= '0'&"000"&s0ext_wr&x"00";
306
                        when x"C" =>
307
                                s0ext_wr_add_one_hot <= '0'&"00"&s0ext_wr&'0'&x"00";
308
                        when x"D" =>
309
                                s0ext_wr_add_one_hot <= '0'&'0'&s0ext_wr&"00"&x"00";
310
                        when x"E" =>
311
                                s0ext_wr_add_one_hot <= '0'&s0ext_wr&"000"&x"00";
312
                        when others =>
313
                                s0ext_wr_add_one_hot <= s0ext_wr&x"000";
314 138 jguarin200
                end case;
315
 
316
        end process;
317 140 jguarin200
 
318
        --! Decodificaci&oacute;n para seleccionar que cola de resultados se conectar&acute; a la salida del RayTrac. 
319 181 jguarin200
 
320 147 jguarin200
        results_block_proc: process(clk,rst)
321 138 jguarin200
        begin
322 147 jguarin200
                if rst=rstMasterValue then
323
                        s0ext_rd_add    <= (others => '0');
324
                        s0ext_rd                <= '0';
325
                elsif clk'event and clk='1' then
326 130 jguarin200
                        --!Registrar entrada
327 138 jguarin200
                        s0ext_rd_add    <= ext_rd_add;
328
                        s0ext_rd                <= ext_rd;
329
                        --!Etapa 0: Decodificar la cola que se va a mover (rdack! fifo showahead mode) y por ende leer ese dato.
330 181 jguarin200
                        case s0ext_rd_add is
331 138 jguarin200
                                when x"0" => ext_q <= s0ext_q(0);
332
                                when x"1" => ext_q <= s0ext_q(1);
333
                                when x"2" => ext_q <= s0ext_q(2);
334
                                when x"3" => ext_q <= s0ext_q(3);
335
                                when x"4" => ext_q <= s0ext_q(4);
336
                                when x"5" => ext_q <= s0ext_q(5);
337
                                when x"6" => ext_q <= s0ext_q(6);
338 181 jguarin200
                                when x"7" => ext_q <= s0ext_q(7);
339
                                when others => ext_q <= x"000000"&s0status_register;
340 130 jguarin200
                        end case;
341
                end if;
342
        end process;
343 140 jguarin200
 
344
        --! rdack decoder para las colas de resultados de salida.
345 181 jguarin200
        results_block_proc_combinatorial_stage: process(s0ext_rd,s0ext_rd_add)
346 138 jguarin200
        begin
347 181 jguarin200
                case s0ext_rd_add(3 downto 0) is
348 138 jguarin200
                        when x"0" => s0ext_rd_ack <= x"0"&"000"&s0ext_rd;
349
                        when x"1" => s0ext_rd_ack <= x"0"&"00"&s0ext_rd&'0';
350
                        when x"2" => s0ext_rd_ack <= x"0"&"0"&s0ext_rd&"00";
351
                        when x"3" => s0ext_rd_ack <= x"0"&s0ext_rd&"000";
352
                        when x"4" => s0ext_rd_ack <= "000"&s0ext_rd&x"0";
353
                        when x"5" => s0ext_rd_ack <= "00"&s0ext_rd&'0'&x"0";
354
                        when x"6" => s0ext_rd_ack <= "0"&s0ext_rd&"00"&x"0";
355 181 jguarin200
                        when x"7" => s0ext_rd_ack <= s0ext_rd&"000"&x"0";
356
                        when others => s0ext_rd_ack <= (others => '0');
357 138 jguarin200
                end case;
358
        end process;
359 181 jguarin200
 
360
        --!Proceso para escribir el status register.
361
 
362
        --!Independiente del valor rfull(i) o si se lee o no, los bits correspondientes a los eventos de cola de resultados llena, se escriben reloj a reloj.
363
        --!Final de Instrucci&oacute;n: Si ocurre un evento de final de instrucci&oacute;n se escribe el bit de registro correspondiente. 
364
        --!Si no hay un evento de final de instrucci&oacute;n entonces se verifica si hay un evento de lectura del status register, si es asi todos los bits correspondientes dentro del registro al evento de fin de instrucci&oacute;n se borran y quedan en cero.
365
        --!Si no hay un evento de final de instrucci&oacite;n y tampoco de lectura del status register entonces se deja el mismo valor del estatus register.
366
        sreg_proc: process (clk,rst,s0ext_rd_add,status_register(3 downto 0))
367
        begin
368
                if rst=rstMasterValue then
369
                        s0status_register(7 downto 0) <= (others => '0');
370
                elsif clk'event and clk='1' then
371
 
372
                        --!Sin importar el valor de las se&ntilde;ales de cola de resultados llena, escribir el registro.
373
                        s0status_register(7) <= sresultfifo_full(7) or sresultfifo_full(6) or sresultfifo_full(5);
374
                        s0status_register(6) <= sresultfifo_full(4) or sresultfifo_full(2);
375
                        s0status_register(5) <= sresultfifo_full(3) or sresultfifo_full(2) or sresultfifo_full(1);
376
                        s0status_register(4) <= sresultfifo_full(0);
377
 
378
                        for i in 3 downto 0 loop
379
                                --! Si hay evento de fin de instrucci&oacute;n entonces escribir en el bit correspondiente un uno.
380
                                if status_register(i)='1' then
381
                                        s0status_register(i) <= '1';
382
                                --! Como no hubo final de instrucci&oacute;n revisar si hay lectura de Status Register y borrarlo.
383
                                elsif s0ext_rd_add(3)='1' then
384
                                        s0status_register(i) <= '0';
385
                                --! No ocurrio nada de lo anterior, dejar entonces en el mismo valor el Status Register.
386
                                else
387
                                        s0status_register(i) <= s0status_register(i);
388
                                end if;
389
                        end loop;
390
                end if;
391
        end process;
392
 
393
 
394 153 jguarin200
end architecture;
395 128 jguarin200
 

powered by: WebSVN 2.1.0

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