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

Subversion Repositories raytrac

[/] [raytrac/] [trunk/] [uf.vhd] - Blame information for rev 35

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

Line No. Rev Author Line
1 22 jguarin200
--! @file raytrac.vhd
2
--! @brief Descripción del sistema aritmetico usado por raytrac.
3
--! @author Julián Andrés Guarín Reyes.
4 8 jguarin200
-- RAYTRAC
5
-- Author Julian Andres Guarin
6
-- uf.vhd
7
-- This file is part of raytrac.
8
-- 
9
--     raytrac is free software: you can redistribute it and/or modify
10
--     it under the terms of the GNU General Public License as published by
11
--     the Free Software Foundation, either version 3 of the License, or
12
--     (at your option) any later version.
13
-- 
14
--     raytrac is distributed in the hope that it will be useful,
15
--     but WITHOUT ANY WARRANTY; without even the implied warranty of
16
--     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
--     GNU General Public License for more details.
18
-- 
19
--     You should have received a copy of the GNU General Public License
20
--     along with raytrac.  If not, see <http://www.gnu.org/licenses/>.
21
 
22 22 jguarin200
--! Libreria de definicion de senales y tipos estandares, comportamiento de operadores aritmeticos y logicos.\n Signal and types definition library. This library also defines 
23 2 jguarin200
library ieee;
24 22 jguarin200
--! Paquete de definicion estandard de logica. Standard logic definition pack.
25 2 jguarin200
use ieee.std_logic_1164.all;
26 27 jguarin200
 
27
--! Paquete para el manejo de aritmŽtica con signo sobre el tipo std_logic_vector 
28
use ieee.std_logic_signed.all;
29
 
30 22 jguarin200
--! Se usaran en esta descripcion los componentes del package arithpack.vhd.\n It will be used in this description the components on the arithpack.vhd package. 
31 2 jguarin200
use work.arithpack.all;
32
 
33 22 jguarin200
 
34
--! uf es la descripción del circuito que realiza la aritmética del Rt Engine.
35
 
36
--! La entrada opcode indica la operación que se está realizando, en los sumadores, es la misma señal que se encuentra en la entidad opcoder, que selecciona si se está realizando un producto punto o un producto cruz. Dentro de la arquitectura de uf, la señal opcode selecciona en la primera etapa de sumadores, si la operación a realizar será una resta o una suma. 
37
--! Los resultados estarán en distintas salidas dependiendo de la operación, lo cual es apenas natural: El producto cruz tiene por resultado un vector, mientras que el producto punto tiene por resultado un escalar. 
38
--! Esta entidad utiliza las señales de control clk y rst.}
39
--! \n\n
40
--! La característica fundamental de uf, es que puede realizar 2 operaciones de producto punto al mimso tiempo ó una operación de producto cruz al mismo tiempo. La otra característica importante es que el pipe de producto punto es mas largo que el pipe de producto cruz: el producto punto tomará 3 clocks para realizarse, mientras que el procto punto tomara 4 clocks para realizarse.    
41
 
42 27 jguarin200
entity uf is
43
        generic (
44 32 jguarin200
                        use_std_logic_signed : string := "NO";
45
                        carry_logic : string := "CLA"
46 27 jguarin200
        );
47 2 jguarin200
        port (
48 22 jguarin200
                opcode          : in std_logic; --! Entrada que dentro de la arquitectura funciona como selector de la operación que se lleva a cabo en la primera etapa de sumadores/restadores. 
49
                m0f0,m0f1,m1f0,m1f1,m2f0,m2f1,m3f0,m3f1,m4f0,m4f1,m5f0,m5f1 : in std_logic_vector(17 downto 0); --! Entradas que van conectadas a los multiplicadores en la primera etapa de la descripción.  
50
                cpx,cpy,cpz,dp0,dp1 : out std_logic_vector(31 downto 0); --! Salidas donde se registran los resultados de las operaciones aritméticas: cpx,cpy,cpz serán los componentes del vector que da por resultado el producto cruz entre los vectores AxB ó CxD.  
51
                clk,rst         : in std_logic --! Las entradas de control usuales.  
52 2 jguarin200
        );
53
end uf;
54
 
55
architecture uf_arch of uf is
56
 
57 8 jguarin200
        -- Stage 0 signals
58 2 jguarin200
 
59 22 jguarin200
        signal stage0mf00,stage0mf01,stage0mf10,stage0mf11,stage0mf20,stage0mf21,stage0mf30,stage0mf31,stage0mf40,stage0mf41,stage0mf50,stage0mf51 : std_logic_vector(17 downto 0); --! Señales que conectan los operandos seleccionados en opcode a las entradas de los multiplicadores.
60
        signal stage0p0,stage0p1, stage0p2, stage0p3, stage0p4, stage0p5 : std_logic_vector(31 downto 0); --! Señales / buses, con los productos de los multiplicadores. 
61 28 jguarin200
        signal stageMopcode : std_logic; --! Señal de atraso del opcode. Revisar el diagrama de bloques para mayor claridad.
62 2 jguarin200
 
63 8 jguarin200
        --Stage 1 signals 
64 2 jguarin200
 
65 22 jguarin200
        signal stage1p0, stage1p1, stage1p2, stage1p3, stage1p4, stage1p5 : std_logic_vector (31 downto 0); --! Señales provenientes de los productos de la etapa previa de multiplicadores.
66
        signal stage1a0, stage1a1, stage1a2 : std_logic_vector (31 downto 0); --! Señales / buses, con los resultados de los sumadores. 
67 28 jguarin200
        signal stageSRopcode : std_logic; --! Señal proveniente del opcode que selecciona si los sumadores deben ejecutar una resta o una suma dependiendo de la operación que se ejecute en ese momento del pipe.  
68 2 jguarin200
 
69 8 jguarin200
        -- Some support signals
70 22 jguarin200
        signal stage1_internalCarry     : std_logic_vector(2 downto 0); --! Cada uno de los 3 sumadores de la etapa de sumadores está compuesto de una cascada de 2 sumadores Carry Look Ahead: aXhigh y aXlow. El carry out del componente low y el carry in del componente high, se conectará a través de las señales internal carry.   
71
        signal stage2_internalCarry : std_logic_vector(1 downto 0); --! Cada uno de los 2 sumadores de la última etapa de sumadores está compuesto de una cascada de 2 sumadores Carry Look AheadÑ: aXhigh y aXlow. El carry out del componente low y el carry in del componente high, se conectará a través de las señales internal carry.  
72 2 jguarin200
 
73 22 jguarin200
        --Stage 2 signals       
74
        signal stage2a0, stage2a2, stage2a3, stage2a4, stage2p2, stage2p3 : std_logic_vector (31 downto 0); --! Estas señales corresponden a los sumandos derivados de la primera etapa de multiplicadores (stage2p2, stage2p3) y a los sumandos derivados del resultado de las sumas en la primera etapa de sumadores. 
75 8 jguarin200
 
76
 
77
 
78 2 jguarin200
begin
79
 
80 8 jguarin200
        -- Multiplicator Instantiation (StAgE 0)
81 22 jguarin200
        --! Multiplicador 0 
82 14 jguarin200
        m0 : r_a18_b18_smul_c32_r
83 8 jguarin200
        port map (
84
                aclr    => rst,
85
                clock   => clk,
86 15 jguarin200
                dataa   => stage0mf00,
87
                datab   => stage0mf01,
88
                result  => stage0p0
89 8 jguarin200
        );
90 22 jguarin200
 
91
        --! Multiplicador 1
92 14 jguarin200
        m1 : r_a18_b18_smul_c32_r
93 8 jguarin200
        port map (
94
                aclr    => rst,
95
                clock   => clk,
96 15 jguarin200
                dataa   => stage0mf10,
97
                datab   => stage0mf11,
98
                result  => stage0p1
99 8 jguarin200
        );
100 22 jguarin200
 
101
        --! Multiplicador 2
102 14 jguarin200
        m2 : r_a18_b18_smul_c32_r
103 8 jguarin200
        port map (
104
                aclr    => rst,
105
                clock   => clk,
106 15 jguarin200
                dataa   => stage0mf20,
107
                datab   => stage0mf21,
108
                result  => stage0p2
109 8 jguarin200
        );
110 22 jguarin200
 
111
        --! Multiplicador 3
112 14 jguarin200
        m3 : r_a18_b18_smul_c32_r
113 8 jguarin200
        port map (
114
                aclr    => rst,
115
                clock   => clk,
116 15 jguarin200
                dataa   => stage0mf30,
117
                datab   => stage0mf31,
118
                result  => stage0p3
119 8 jguarin200
        );
120 22 jguarin200
 
121
        --! Multiplicador 4
122 14 jguarin200
        m4 : r_a18_b18_smul_c32_r
123 8 jguarin200
        port map (
124
                aclr    => rst,
125
                clock   => clk,
126 15 jguarin200
                dataa   => stage0mf40,
127
                datab   => stage0mf41,
128
                result  => stage0p4
129 8 jguarin200
        );
130 22 jguarin200
 
131
        --! Multiplicador 5
132 14 jguarin200
        m5 : r_a18_b18_smul_c32_r
133 8 jguarin200
        port map (
134
                aclr    => rst,
135
                clock   => clk,
136 15 jguarin200
                dataa   => stage0mf50,
137
                datab   => stage0mf51,
138
                result  => stage0p5
139 8 jguarin200
        );
140
 
141
 
142
 
143 27 jguarin200
        useIeee:
144
        if use_std_logic_signed="YES" generate
145
                -- Adder Instantiation (sTaGe 1)
146
                stage1adderProc:
147 28 jguarin200
                process (stage1p0,stage1p1,stage1p2,stage1p3,stage1p4,stage1p5,stageSRopcode)
148 27 jguarin200
                begin
149 28 jguarin200
                        case (stageSRopcode) is
150 27 jguarin200
                                when '1' =>             -- Cross Product
151
                                        stage1a0 <= stage1p0-stage1p1;
152
                                        stage1a2 <= stage1p4-stage1p5;
153
                                when others =>  -- Dot Product
154
                                        stage1a0 <= stage1p0+stage1p1;
155
                                        stage1a2 <= stage1p4+stage1p5;
156
                        end case;
157
                end process stage1adderProc;
158
                stage1a1 <= stage1p2-stage1p3;  -- This is always going to be a substraction
159
 
160
                -- Adder Instantiation (Stage 2)
161
                stage2a3 <= stage2a0+stage2p2;
162
                stage2a4 <= stage2p3+stage2a2;
163
        end generate useIeee;
164
        dontUseIeee:
165
        if use_std_logic_signed="NO" generate
166
                --! Adder 0, 16 bit carry lookahead low adder.
167
                a0low : adder
168 32 jguarin200
                generic map (16,carry_logic,"YES")      -- Carry Look Ahead Logic (More Gates Used, But Less Time)
169 27 jguarin200
                                                                                -- Yes instantiate Xor gates stage in the adder so we can substract on the opcode signal command.
170 28 jguarin200
                port map        (stage1p0(15 downto 0),stage1p1(15 downto 0),stageSRopcode,'0',stage1a0(15 downto 0),stage1_internalCarry(0));
171 27 jguarin200
                --Adder 0, 16 bit carry lookahead high adder.
172
                a0high : adder
173 32 jguarin200
                generic map (16,carry_logic,"YES")      -- Carry Look Ahead Logic (More Gates Used, But Less Time)
174 27 jguarin200
                                                                                -- Yes instantiate Xor gates stage in the adder so we can substract on the opcode signal command.
175 28 jguarin200
                port map        (stage1p0(31 downto 16),stage1p1(31 downto 16),stageSRopcode,stage1_internalCarry(0),stage1a0(31 downto 16),open);
176 27 jguarin200
                --! Adder 1, 16 bit carry lookahead low adder. 
177
                a1low : adder
178 32 jguarin200
                generic map (16,carry_logic,"YES")      -- Carry Look Ahead Logic (More Gates Used, But Less Time)
179 27 jguarin200
                                                                                -- Yes instantiate Xor gates stage in the adder so we can substract on the opcode signal command.
180
                port map        (stage1p2(15 downto 0),stage1p3(15 downto 0),'1','0',stage1a1(15 downto 0),stage1_internalCarry(1));
181
                --! Adder 1, 16 bit carry lookahead high adder.
182
                a1high : adder
183 32 jguarin200
                generic map (16,carry_logic,"YES")      -- Carry Look Ahead Logic (More Gates Used, But Less Time)
184 27 jguarin200
                                                                                -- Yes instantiate Xor gates stage in the adder so we can substract on the opcode signal command.
185
                port map        (stage1p2(31 downto 16),stage1p3(31 downto 16),'1',stage1_internalCarry(1),stage1a1(31 downto 16),open);
186
                --! Adder 2, 16 bit carry lookahead low adder. 
187
                a2low : adder
188 32 jguarin200
                generic map (16,carry_logic,"YES")      -- Carry Look Ahead Logic (More Gates Used, But Less Time)
189 27 jguarin200
                                                                                -- Yes instantiate Xor gates stage in the adder so we can substract on the opcode signal command.
190 28 jguarin200
                port map        (stage1p4(15 downto 0),stage1p5(15 downto 0),stageSRopcode,'0',stage1a2(15 downto 0),stage1_internalCarry(2));
191 27 jguarin200
                --! Adder 2, 16 bit carry lookahead high adder.
192
                a2high : adder
193 32 jguarin200
                generic map (16,carry_logic,"YES")      -- Carry Look Ahead Logic (More Gates Used, But Less Time)
194 27 jguarin200
                                                                                -- Yes instantiate Xor gates stage in the adder so we can substract on the opcode signal command.
195 28 jguarin200
                port map        (stage1p4(31 downto 16),stage1p5(31 downto 16),stageSRopcode,stage1_internalCarry(2),stage1a2(31 downto 16),open);
196 27 jguarin200
                -- Adder Instantiation (Stage 2)
197
                --! Adder 3, 16 bit carry lookahead low adder. 
198
                a3low : adder
199 32 jguarin200
                generic map (16,carry_logic,"NO")               -- Carry Look Ahead Logic (More Gates Used, But Less Time)
200 27 jguarin200
                                                                                -- Dont instantiate Xor gates stage in the adder.
201
                port map        (stage2a0(15 downto 0),stage2p2(15 downto 0),'0','0',stage2a3(15 downto 0),stage2_internalCarry(0));
202
                --Adder 3, 16 bit carry lookahead high adder.
203
                a3high : adder
204 32 jguarin200
                generic map (16,carry_logic,"NO")               -- Carry Look Ahead Logic (More Gates Used, But Less Time)
205 27 jguarin200
                                                                                -- Dont instantiate Xor gates stage in the adder.
206
                port map        (stage2a0(31 downto 16),stage2p2(31 downto 16),'0',stage2_internalCarry(0),stage2a3(31 downto 16),open);
207
                --! Adder 4, 16 bit carry lookahead low adder. 
208
                a4low : adder
209 32 jguarin200
                generic map (16,carry_logic,"NO")               -- Carry Look Ahead Logic (More Gates Used, But Less Time)
210 27 jguarin200
                                                                                -- Dont instantiate Xor gates stage in the adder.
211
                port map        (stage2p3(15 downto 0),stage2a2(15 downto 0),'0','0',stage2a4(15 downto 0),stage2_internalCarry(1));
212
                --! Adder 4, 16 bit carry lookahead high adder.
213
                a4high : adder
214 32 jguarin200
                generic map (16,carry_logic,"NO")               -- Carry Look Ahead Logic (More Gates Used, But Less Time)
215 27 jguarin200
                                                                                -- Dont instantiate Xor gates stage in the adder.
216
                port map        (stage2p3(31 downto 16),stage2a2(31 downto 16),'0',stage2_internalCarry(1),stage2a4(31 downto 16),open);
217
 
218
        end generate dontUseIeee;
219 8 jguarin200
        -- Incoming from opcoder.vhd signals into pipeline's stage 0.
220 15 jguarin200
        stage0mf00 <= m0f0;
221
        stage0mf01 <= m0f1;
222
        stage0mf10 <= m1f0;
223
        stage0mf11 <= m1f1;
224
        stage0mf20 <= m2f0;
225
        stage0mf21 <= m2f1;
226
        stage0mf30 <= m3f0;
227
        stage0mf31 <= m3f1;
228
        stage0mf40 <= m4f0;
229
        stage0mf41 <= m4f1;
230
        stage0mf50 <= m5f0;
231
        stage0mf51 <= m5f1;
232 8 jguarin200
 
233
        -- Signal sequencing: as the multipliers use registered output and registered input is not necessary to write the sequence of stage 0 signals to stage 1 signals.
234
        -- so the simplistic path is taken: simply connect stage 0 to stage 1 lines. However this would not apply for the opcode signal
235 15 jguarin200
        stage1p0 <= stage0p0;
236
        stage1p1 <= stage0p1;
237
        stage1p2 <= stage0p2;
238
        stage1p3 <= stage0p3;
239
        stage1p4 <= stage0p4;
240
        stage1p5 <= stage0p5;
241 8 jguarin200
 
242
 
243
        --Outcoming to the rest of the system (by the time i wrote this i dont know where this leads to... jeje)
244 15 jguarin200
        cpx <= stage1a0;
245
        cpy <= stage1a1;
246
        cpz <= stage1a2;
247
        dp0 <= stage2a3;
248
        dp1 <= stage2a4;
249 8 jguarin200
 
250
        -- Looking into the design the stage 1 to stage 2 are the sequences pipe stages that must be controlled in this particular HDL.
251 22 jguarin200
        --! Este proceso describe la manera en que se organizan las etapas de pipe.
252 28 jguarin200
        --! Todas las señales internas en las etapas de pipe, en el momento en que la entrada rst alcanza el nivel rstMasterValue, se colocan en '0'. Nótese que, salvo stageMopcode<=stageSRopcode, las señales que vienen desde la entrada hacia los multiplicadores en la etapa 0 y desde la salida de los multiplicadores desde la etapa0 hacia la etapa 1, no están siendo descritas en este proceso, la explicación de es simple: Los multiplicadores que se están instanciado tienen registros a la entrada y la salida, permitiendo así, registrar las entradas y registrar los productos o salidas de los  multiplicadores, hacia la etapa 1 o etapa de sumadores/restadores. 
253 22 jguarin200
 
254
        uf_seq: process (clk,rst)
255 8 jguarin200
        begin
256
 
257
                if rst=rstMasterValue then
258 28 jguarin200
                        stageMopcode    <= '0';
259
                        stageSRopcode   <= '0';
260 3 jguarin200
 
261 15 jguarin200
                        stage2a2 <= (others => '0');
262
                        stage2p3 <= (others => '0');
263
                        stage2p2 <= (others => '0');
264
                        stage2a0 <= (others => '0');
265 8 jguarin200
 
266
                elsif clk'event and clk = '1' then
267
 
268 15 jguarin200
                        stage2a2 <= stage1a2;
269
                        stage2p3 <= stage1p3;
270
                        stage2p2 <= stage1p2;
271
                        stage2a0 <= stage1a0;
272 3 jguarin200
 
273 8 jguarin200
                        -- Opcode control sequence
274 28 jguarin200
                        stageMopcode <= opcode;
275
                        stageSRopcode <= stageMopcode;
276 8 jguarin200
 
277
                end if;
278
        end process uf_seq;
279 15 jguarin200
 
280
 
281
 
282 2 jguarin200
end uf_arch;

powered by: WebSVN 2.1.0

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