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

Subversion Repositories raytrac

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

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

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

powered by: WebSVN 2.1.0

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