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

Subversion Repositories raytrac

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

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 28 jguarin200
                        use_std_logic_signed : string := "NO"
45 27 jguarin200
        );
46 2 jguarin200
        port (
47 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. 
48
                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.  
49
                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.  
50
                clk,rst         : in std_logic --! Las entradas de control usuales.  
51 2 jguarin200
        );
52
end uf;
53
 
54
architecture uf_arch of uf is
55
 
56 8 jguarin200
        -- Stage 0 signals
57 2 jguarin200
 
58 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.
59
        signal stage0p0,stage0p1, stage0p2, stage0p3, stage0p4, stage0p5 : std_logic_vector(31 downto 0); --! Señales / buses, con los productos de los multiplicadores. 
60 28 jguarin200
        signal stageMopcode : std_logic; --! Señal de atraso del opcode. Revisar el diagrama de bloques para mayor claridad.
61 2 jguarin200
 
62 8 jguarin200
        --Stage 1 signals 
63 2 jguarin200
 
64 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.
65
        signal stage1a0, stage1a1, stage1a2 : std_logic_vector (31 downto 0); --! Señales / buses, con los resultados de los sumadores. 
66 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.  
67 2 jguarin200
 
68 8 jguarin200
        -- Some support signals
69 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.   
70
        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.  
71 2 jguarin200
 
72 22 jguarin200
        --Stage 2 signals       
73
        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. 
74 8 jguarin200
 
75
 
76
 
77 2 jguarin200
begin
78
 
79 8 jguarin200
        -- Multiplicator Instantiation (StAgE 0)
80 22 jguarin200
        --! Multiplicador 0 
81 14 jguarin200
        m0 : r_a18_b18_smul_c32_r
82 8 jguarin200
        port map (
83
                aclr    => rst,
84
                clock   => clk,
85 15 jguarin200
                dataa   => stage0mf00,
86
                datab   => stage0mf01,
87
                result  => stage0p0
88 8 jguarin200
        );
89 22 jguarin200
 
90
        --! Multiplicador 1
91 14 jguarin200
        m1 : r_a18_b18_smul_c32_r
92 8 jguarin200
        port map (
93
                aclr    => rst,
94
                clock   => clk,
95 15 jguarin200
                dataa   => stage0mf10,
96
                datab   => stage0mf11,
97
                result  => stage0p1
98 8 jguarin200
        );
99 22 jguarin200
 
100
        --! Multiplicador 2
101 14 jguarin200
        m2 : r_a18_b18_smul_c32_r
102 8 jguarin200
        port map (
103
                aclr    => rst,
104
                clock   => clk,
105 15 jguarin200
                dataa   => stage0mf20,
106
                datab   => stage0mf21,
107
                result  => stage0p2
108 8 jguarin200
        );
109 22 jguarin200
 
110
        --! Multiplicador 3
111 14 jguarin200
        m3 : r_a18_b18_smul_c32_r
112 8 jguarin200
        port map (
113
                aclr    => rst,
114
                clock   => clk,
115 15 jguarin200
                dataa   => stage0mf30,
116
                datab   => stage0mf31,
117
                result  => stage0p3
118 8 jguarin200
        );
119 22 jguarin200
 
120
        --! Multiplicador 4
121 14 jguarin200
        m4 : r_a18_b18_smul_c32_r
122 8 jguarin200
        port map (
123
                aclr    => rst,
124
                clock   => clk,
125 15 jguarin200
                dataa   => stage0mf40,
126
                datab   => stage0mf41,
127
                result  => stage0p4
128 8 jguarin200
        );
129 22 jguarin200
 
130
        --! Multiplicador 5
131 14 jguarin200
        m5 : r_a18_b18_smul_c32_r
132 8 jguarin200
        port map (
133
                aclr    => rst,
134
                clock   => clk,
135 15 jguarin200
                dataa   => stage0mf50,
136
                datab   => stage0mf51,
137
                result  => stage0p5
138 8 jguarin200
        );
139
 
140
 
141
 
142 27 jguarin200
        useIeee:
143
        if use_std_logic_signed="YES" generate
144
                -- Adder Instantiation (sTaGe 1)
145
                stage1adderProc:
146 28 jguarin200
                process (stage1p0,stage1p1,stage1p2,stage1p3,stage1p4,stage1p5,stageSRopcode)
147 27 jguarin200
                begin
148 28 jguarin200
                        case (stageSRopcode) is
149 27 jguarin200
                                when '1' =>             -- Cross Product
150
                                        stage1a0 <= stage1p0-stage1p1;
151
                                        stage1a2 <= stage1p4-stage1p5;
152
                                when others =>  -- Dot Product
153
                                        stage1a0 <= stage1p0+stage1p1;
154
                                        stage1a2 <= stage1p4+stage1p5;
155
                        end case;
156
                end process stage1adderProc;
157
                stage1a1 <= stage1p2-stage1p3;  -- This is always going to be a substraction
158
 
159
                -- Adder Instantiation (Stage 2)
160
                stage2a3 <= stage2a0+stage2p2;
161
                stage2a4 <= stage2p3+stage2a2;
162
        end generate useIeee;
163
        dontUseIeee:
164
        if use_std_logic_signed="NO" generate
165
                --! Adder 0, 16 bit carry lookahead low adder.
166
                a0low : adder
167
                generic map (16,"CLA","YES")    -- Carry Look Ahead Logic (More Gates Used, But Less Time)
168
                                                                                -- Yes instantiate Xor gates stage in the adder so we can substract on the opcode signal command.
169 28 jguarin200
                port map        (stage1p0(15 downto 0),stage1p1(15 downto 0),stageSRopcode,'0',stage1a0(15 downto 0),stage1_internalCarry(0));
170 27 jguarin200
                --Adder 0, 16 bit carry lookahead high adder.
171
                a0high : adder
172
                generic map (16,"CLA","YES")    -- Carry Look Ahead Logic (More Gates Used, But Less Time)
173
                                                                                -- Yes instantiate Xor gates stage in the adder so we can substract on the opcode signal command.
174 28 jguarin200
                port map        (stage1p0(31 downto 16),stage1p1(31 downto 16),stageSRopcode,stage1_internalCarry(0),stage1a0(31 downto 16),open);
175 27 jguarin200
                --! Adder 1, 16 bit carry lookahead low adder. 
176
                a1low : adder
177
                generic map (16,"CLA","YES")    -- Carry Look Ahead Logic (More Gates Used, But Less Time)
178
                                                                                -- Yes instantiate Xor gates stage in the adder so we can substract on the opcode signal command.
179
                port map        (stage1p2(15 downto 0),stage1p3(15 downto 0),'1','0',stage1a1(15 downto 0),stage1_internalCarry(1));
180
                --! Adder 1, 16 bit carry lookahead high adder.
181
                a1high : adder
182
                generic map (16,"CLA","YES")    -- Carry Look Ahead Logic (More Gates Used, But Less Time)
183
                                                                                -- Yes instantiate Xor gates stage in the adder so we can substract on the opcode signal command.
184
                port map        (stage1p2(31 downto 16),stage1p3(31 downto 16),'1',stage1_internalCarry(1),stage1a1(31 downto 16),open);
185
                --! Adder 2, 16 bit carry lookahead low adder. 
186
                a2low : adder
187
                generic map (16,"CLA","YES")    -- Carry Look Ahead Logic (More Gates Used, But Less Time)
188
                                                                                -- Yes instantiate Xor gates stage in the adder so we can substract on the opcode signal command.
189 28 jguarin200
                port map        (stage1p4(15 downto 0),stage1p5(15 downto 0),stageSRopcode,'0',stage1a2(15 downto 0),stage1_internalCarry(2));
190 27 jguarin200
                --! Adder 2, 16 bit carry lookahead high adder.
191
                a2high : adder
192
                generic map (16,"CLA","YES")    -- Carry Look Ahead Logic (More Gates Used, But Less Time)
193
                                                                                -- Yes instantiate Xor gates stage in the adder so we can substract on the opcode signal command.
194 28 jguarin200
                port map        (stage1p4(31 downto 16),stage1p5(31 downto 16),stageSRopcode,stage1_internalCarry(2),stage1a2(31 downto 16),open);
195 27 jguarin200
                -- Adder Instantiation (Stage 2)
196
                --! Adder 3, 16 bit carry lookahead low adder. 
197
                a3low : adder
198
                generic map (16,"CLA","NO")             -- Carry Look Ahead Logic (More Gates Used, But Less Time)
199
                                                                                -- Dont instantiate Xor gates stage in the adder.
200
                port map        (stage2a0(15 downto 0),stage2p2(15 downto 0),'0','0',stage2a3(15 downto 0),stage2_internalCarry(0));
201
                --Adder 3, 16 bit carry lookahead high adder.
202
                a3high : adder
203
                generic map (16,"CLA","NO")             -- Carry Look Ahead Logic (More Gates Used, But Less Time)
204
                                                                                -- Dont instantiate Xor gates stage in the adder.
205
                port map        (stage2a0(31 downto 16),stage2p2(31 downto 16),'0',stage2_internalCarry(0),stage2a3(31 downto 16),open);
206
                --! Adder 4, 16 bit carry lookahead low adder. 
207
                a4low : adder
208
                generic map (16,"CLA","NO")             -- Carry Look Ahead Logic (More Gates Used, But Less Time)
209
                                                                                -- Dont instantiate Xor gates stage in the adder.
210
                port map        (stage2p3(15 downto 0),stage2a2(15 downto 0),'0','0',stage2a4(15 downto 0),stage2_internalCarry(1));
211
                --! Adder 4, 16 bit carry lookahead high adder.
212
                a4high : adder
213
                generic map (16,"CLA","NO")             -- Carry Look Ahead Logic (More Gates Used, But Less Time)
214
                                                                                -- Dont instantiate Xor gates stage in the adder.
215
                port map        (stage2p3(31 downto 16),stage2a2(31 downto 16),'0',stage2_internalCarry(1),stage2a4(31 downto 16),open);
216
 
217
        end generate dontUseIeee;
218 8 jguarin200
        -- Incoming from opcoder.vhd signals into pipeline's stage 0.
219 15 jguarin200
        stage0mf00 <= m0f0;
220
        stage0mf01 <= m0f1;
221
        stage0mf10 <= m1f0;
222
        stage0mf11 <= m1f1;
223
        stage0mf20 <= m2f0;
224
        stage0mf21 <= m2f1;
225
        stage0mf30 <= m3f0;
226
        stage0mf31 <= m3f1;
227
        stage0mf40 <= m4f0;
228
        stage0mf41 <= m4f1;
229
        stage0mf50 <= m5f0;
230
        stage0mf51 <= m5f1;
231 8 jguarin200
 
232
        -- 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.
233
        -- so the simplistic path is taken: simply connect stage 0 to stage 1 lines. However this would not apply for the opcode signal
234 15 jguarin200
        stage1p0 <= stage0p0;
235
        stage1p1 <= stage0p1;
236
        stage1p2 <= stage0p2;
237
        stage1p3 <= stage0p3;
238
        stage1p4 <= stage0p4;
239
        stage1p5 <= stage0p5;
240 8 jguarin200
 
241
 
242
        --Outcoming to the rest of the system (by the time i wrote this i dont know where this leads to... jeje)
243 15 jguarin200
        cpx <= stage1a0;
244
        cpy <= stage1a1;
245
        cpz <= stage1a2;
246
        dp0 <= stage2a3;
247
        dp1 <= stage2a4;
248 8 jguarin200
 
249
        -- Looking into the design the stage 1 to stage 2 are the sequences pipe stages that must be controlled in this particular HDL.
250 22 jguarin200
        --! Este proceso describe la manera en que se organizan las etapas de pipe.
251 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. 
252 22 jguarin200
 
253
        uf_seq: process (clk,rst)
254 8 jguarin200
        begin
255
 
256
                if rst=rstMasterValue then
257 28 jguarin200
                        stageMopcode    <= '0';
258
                        stageSRopcode   <= '0';
259 3 jguarin200
 
260 15 jguarin200
                        stage2a2 <= (others => '0');
261
                        stage2p3 <= (others => '0');
262
                        stage2p2 <= (others => '0');
263
                        stage2a0 <= (others => '0');
264 8 jguarin200
 
265
                elsif clk'event and clk = '1' then
266
 
267 15 jguarin200
                        stage2a2 <= stage1a2;
268
                        stage2p3 <= stage1p3;
269
                        stage2p2 <= stage1p2;
270
                        stage2a0 <= stage1a0;
271 3 jguarin200
 
272 8 jguarin200
                        -- Opcode control sequence
273 28 jguarin200
                        stageMopcode <= opcode;
274
                        stageSRopcode <= stageMopcode;
275 8 jguarin200
 
276
                end if;
277
        end process uf_seq;
278 15 jguarin200
 
279
 
280
 
281 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.