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

Subversion Repositories raytrac

[/] [raytrac/] [trunk/] [fpbranch/] [add/] [ema32x2.vhd] - Blame information for rev 136

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

Line No. Rev Author Line
1 88 jguarin200
------------------------------------------------
2 102 jguarin200
--! @file ema32x2.vhd
3 100 jguarin200
--! @brief RayTrac Floating Point Adder  
4 88 jguarin200
--! @author Julián Andrés Guarín Reyes
5
--------------------------------------------------
6
 
7
 
8
-- RAYTRAC (FP BRANCH)
9
-- Author Julian Andres Guarin
10 102 jguarin200
-- ema32x2.vhd
11 88 jguarin200
-- This file is part of raytrac.
12
-- 
13
--     raytrac is free software: you can redistribute it and/or modify
14
--     it under the terms of the GNU General Public License as published by
15
--     the Free Software Foundation, either version 3 of the License, or
16
--     (at your option) any later version.
17
-- 
18
--     raytrac is distributed in the hope that it will be useful,
19
--     but WITHOUT ANY WARRANTY; without even the implied warranty of
20
--     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
--     GNU General Public License for more details.
22
-- 
23
--     You should have received a copy of the GNU General Public License
24
--     along with raytrac.  If not, see <http://www.gnu.org/licenses/>
25
 
26 84 jguarin200
library ieee;
27
use ieee.std_logic_1164.all;
28
use ieee.std_logic_unsigned.all;
29
use ieee.std_logic_arith.all;
30
 
31 93 jguarin200
 
32 88 jguarin200
--! Esta entidad recibe dos n&uacutemeros en formato punto flotante IEEE 754, de precision simple y devuelve las mantissas signadas y corridas, y el exponente correspondiente al resultado antes de normalizarlo al formato float. 
33
--!\nLas 2 mantissas y el exponente entran despues a la entidad add2 que suma las mantissas y entrega el resultado en formato IEEE 754.
34 102 jguarin200
entity ema32x2 is
35 84 jguarin200
        port (
36 93 jguarin200
                clk,dpc         : in std_logic;
37 84 jguarin200
                a32,b32         : in std_logic_vector (31 downto 0);
38 93 jguarin200
                res32           : out std_logic_vector(31 downto 0)
39 84 jguarin200
        );
40 102 jguarin200
end ema32x2;
41 84 jguarin200
 
42 102 jguarin200
architecture ema32x2_arch of ema32x2 is
43 100 jguarin200
 
44 106 jguarin200
        component shftr
45 91 jguarin200
        port (
46 106 jguarin200
                dir             : in std_logic;
47
                places  : in std_logic_vector (3 downto 0);
48
                data24  : in std_logic_vector (23 downto 0);
49
                data40  : out std_logic_vector (39 downto 0)
50 91 jguarin200
        );
51 106 jguarin200
        end component;
52
 
53 95 jguarin200
        signal s2slr                                                                            : std_logic_vector(1 downto 0);
54
        signal s3lshift,s4lshift                                                        : std_logic_vector(4 downto 0);
55 106 jguarin200
        signal s0sdelta,s0udelta,s0udeltaa,s0udeltab,s2exp,s3exp,s4exp          : std_logic_vector(7 downto 0);
56 95 jguarin200
        signal s4slab                                                                           : std_logic_vector(15 downto 0);
57
        signal s2slab                                                                           : std_logic_vector(16 downto 0);
58
        signal b1s,s4nrmP                                                                       : std_logic_vector(22 downto 0); -- Inversor de la mantissa
59 102 jguarin200
        signal s0a,s0b,s1a,s1b                                                          : std_logic_vector(31 downto 0); -- Float 32 bit 
60 95 jguarin200
        signal s1sma,s2sma,s2smb,s3sma,s3smb,s3ures,s4ures      : std_logic_vector(24 downto 0); -- Signed mantissas
61
        signal s3res                                                                            : std_logic_vector(25 downto 0); -- Signed mantissa result
62
        signal s1pS,s1pH,s1pL,s4nrmL,s4nrmH,s4nrmS                      : std_logic_vector(17 downto 0); -- Shifert Product
63 106 jguarin200
        signal s0zeroa,s0zerob,s1zeroa,s1zerob,s1z,s4sgr                        : std_logic;
64 107 jguarin200
        signal s2sma,s2smb                                                                      : std_logic_vector (56 downto 0);
65 91 jguarin200
 
66 84 jguarin200
begin
67
 
68
        process (clk)
69
        begin
70
                if clk'event and clk='1' then
71
 
72
                        --!Registro de entrada
73 95 jguarin200
                        s0a <= a32;
74 106 jguarin200
 
75 98 jguarin200
                        s0b(31) <= dpc xor b32(31);     --! Importante: Integrar el signo en el operando B
76
                        s0b(30 downto 0) <= b32(30 downto 0);
77 106 jguarin200
                        s0b(22 downto 0) <= b32(22 downto 0);
78
 
79
                        --!Etapa 0,Calcular la manera en que se llevara a cabo la desnormalizacion
80 107 jguarin200
                        s1signa         <= s0a(31);
81
                        s1signb         <= s0b(31);
82 106 jguarin200
                        s1dira          <= s0sdelta(7);
83
                        s1uma           <= s0a(22 downto 0);
84
                        s1umb           <= s0b(22 downto 0);
85 107 jguarin200
                        if sa(30 downto 23) = "00000000" or sb(30 downto 23) = "00000000" then
86 106 jguarin200
                                s1expb  <= s0b(30 downto 23) or s0a(30 downto 23);
87
                                s1udeltaa       <= "0000";
88
                                s1udeltab       <= "0000";
89 107 jguarin200
                                s1zero          <= '1';
90 84 jguarin200
                        else
91 106 jguarin200
                                s1expb  <= s0b(30 downto 23);
92
                                s1udeltaa       <= s0udeltaa(3 downto 0);
93
                                s1udeltab       <= s1udeltab(3 downto 0);
94 107 jguarin200
                                s1zero  <= '0';
95 84 jguarin200
                        end if;
96 106 jguarin200
 
97
 
98 95 jguarin200
                        --! Etapa 1: Denormalizaci&oacute;n de las mantissas.  
99
                        --! A
100
                        s2exp <= s1a(30 downto 23);
101
                        s2sma <= s1sma;
102 84 jguarin200
 
103 95 jguarin200
                        --! B
104
                        for i in 23 downto 15 loop
105
                                s2smb(i)        <= s1pL(23-i) xor s1b(31);
106 91 jguarin200
                        end loop;
107 95 jguarin200
                        for i in 14 downto 6 loop
108
                                s2smb(i)        <= (s1pH(14-i) or s1pL(14-i+9)) xor s1b(31);
109
                        end loop;
110
                        for i in 5 downto 0 loop
111
                                s2smb(i)        <= (s1pS(5-i) or s1pH(5-i+9)) xor s1b(31);
112 91 jguarin200
                        end loop;
113 95 jguarin200
 
114
                        if s1b(30 downto 28)>"000" then
115
                                s2slr <= "11";
116
                        else
117
                                s2slr <= s1b(27 downto 26);
118
                        end if;
119 91 jguarin200
 
120 95 jguarin200
                        s2smb(24) <= s1b(31);
121 91 jguarin200
 
122 95 jguarin200
                        --! Etapa2: Finalizar la denormalizaci&oacute;n de b.
123
                        --! A
124
                        s3sma <= s2sma;
125
                        s3exp <= s2exp;
126 93 jguarin200
 
127 95 jguarin200
                        --! B
128
                        case (s2slr) is
129
                                when "00" =>
130
                                        s3smb   <= s2smb(24 downto 0)+s2smb(24);
131
                                when "01" =>
132
                                        s3smb   <= ( s2slab(8 downto 0) & s2smb(23 downto 8) ) + s2smb(24);
133
                                when "10"  =>
134
                                        s3smb   <= ( s2slab(16 downto 0) & s2smb(23 downto 16)) + s2smb(24);
135
                                when others =>
136
                                        s3smb   <= (others => '0');
137
                        end case;
138
 
139 93 jguarin200
 
140 95 jguarin200
                        --! Etapa 3: Etapa 3 Realizar la suma, quitar el signo de la mantissa y codificar el corrimiento hacia la izquierda.
141
                        s4ures  <= s3ures+s3res(25);                            --Resultado no signado
142 98 jguarin200
                        s4sgr   <= s3res(25);                                           --Signo
143 95 jguarin200
                        s4exp   <= s3exp;                                                       --Exponente 
144
                        s4lshift <= s3lshift;                                           --Corrimiento hacia la izquierda. 
145
 
146
                        --! Etapa 4: Corrimiento y normalizaci&oacute;n de la mantissa resultado.
147
                        res32(31) <= s4sgr;
148
                        if s4ures(24)='1' then
149
                                res32(22 downto 0) <= s4ures(23 downto 1);
150
                                res32(30 downto 23) <= s4exp+1;
151 93 jguarin200
                        else
152 95 jguarin200
                                case s4lshift(4 downto 3) is
153
                                        when "00" =>
154
                                                res32(22 downto 0)       <= s4nrmP(22 downto 0);
155
                                                res32(30 downto 23) <= s4exp - s4lshift;
156
                                        when "01" =>
157
                                                res32(22 downto 0)       <= s4nrmP(14 downto 0)   & s4slab(7 downto 0);
158
                                                res32(30 downto 23) <= s4exp - s4lshift;
159
                                        when "10" =>
160
                                                res32(22 downto 0)       <= s4nrmP(6 downto 0)    & s4slab(15 downto 0);
161
                                                res32(30 downto 23) <= s4exp - s4lshift;
162
                                        when others =>
163
                                                res32(30 downto 0) <= (others => '0');
164
                                end case;
165
 
166 93 jguarin200
                        end if;
167
 
168 84 jguarin200
                end if;
169
        end process;
170 106 jguarin200
        --! Combinatorial gremlin, Etapa 0, Calcular la manera en que se llevara a cabo la desnormalizacion.
171 95 jguarin200
        process (s0b(30 downto 23),s0a(30 downto 23))
172 88 jguarin200
        begin
173 106 jguarin200
                --! Diferencia signada entre el valor del exponente a y el exponente b
174
                s0sdelta <= s0a(30 downto 23) - s0b(30 downto 23);
175
 
176
                --! Manejo de cero
177
                if sa(30 downto 23) = "00000000" then
178
                        s0zeroa <= '0';
179
                else
180
                        s0zeroa <= '1';
181
                end if;
182
 
183
                if sb(30 downto 23) = "00000000" then
184
                        s0zerob <= '0';
185
                else
186
                        s0zerob <= '1';
187
                end if;
188
 
189
 
190
        end process;
191
 
192
        process (s0sdelta)
193
        begin
194
                --! Esta parte define en que rango de la grafica de normalizac&oacute;n se movera la normalizaci—n del resultado de la mantissa
195
                case s0sdelta(7 downto 1) is
196
                        when "0000000" =>
197
                                s0nrmshftype <= '0';
198
                        when "1111111" =>
199
                                s0nrmshftype <= not(s0sdelta(0));
200
                        when others =>
201
                                s0nrmshftype <= '1';
202
                end case;
203
 
204
                --! Valor absoluto de la diferencia entre el exponente a y el b
205
                for i in 7 downto 0 loop
206
                        s0udelta(i) <= s0sdelta(7) xor s0sdelta(i);
207 88 jguarin200
                end loop;
208 106 jguarin200
 
209
 
210
        end process
211
 
212
        process (s0udelta,s0sdelta(7))
213
        begin
214
                s0udeltaa <= (s0udelta(7)&s0udelta(7 downto 1))+("0000000"&s0sdelta(7));
215
                s0udeltab <= (s0udelta(7)&s0udelta(7 downto 1))+("0000000"&s0udelta(0));
216 88 jguarin200
        end process;
217 95 jguarin200
 
218
 
219 106 jguarin200
        --! Combinatorial Gremlin, Etapa 1 Denormalizaci&oacute;n de las mantissas.
220
        shftra:shftr
221 107 jguarin200
        port    map (s1dira,s1udeltaa(3 downto 0),'1'&s1uma,s1data40a);
222
        shftrb:shftr
223
        port    map (not(s1dira),s1udeltab(3 downto 0),'1'&s1umb,s1data40b);
224
 
225
        process (s1data40b,s1data40a)
226
        begin
227 106 jguarin200
 
228 107 jguarin200
                if s1dira='1' then
229
                        s1signeddata56a(55 downto 40) <= (others => '0');
230
                        s1signeddata56b(15 downto 0) <= (others => '0');
231
                        for i in 39 downto 0 loop
232
                                s1signeddata56a(i)  <= s1signa xor s1data40a(i);
233
                                s1signeddata56b(i+16) <= s1signb xor s1data40b(i);
234
                        end loop;
235
                else
236
                        s1signeddata56a(15 downto 0) <= (others => '0');
237
                        s1signeddata56b(55 downto 40) <= (others => '0');
238
                        for i in 39 downto 0 loop
239
                                s1signeddata56a(i+16)  <= s1signa xor s1data40a(i);
240
                                s1signeddata56b(i) <= s1signb xor s1data40b(i);
241
                        end loop;
242
                end if;
243
        end process;
244 95 jguarin200
        s1b2b1s:
245 91 jguarin200
        for i in 22 downto 0 generate
246 95 jguarin200
                b1s(i) <= s1b(22-i);
247
        end generate s1b2b1s;
248
        signa:
249
        for i in 22 downto 0 generate
250
                s1sma(i) <= s1a(31) xor s1a(i);
251
        end generate;
252
        s1sma(23) <= not(s1a(31));
253
        s1sma(24) <= s1a(31);
254
        --! Combinatorial Gremlin, Etapa2: Finalizar la denormalizaci&oacute;n de b.
255
        s2signslab:
256
        for i in 16 downto 0 generate
257
                s2slab(i) <= s2smb(24);
258
        end generate s2signslab;
259
        --! Combinatorial Gremlin, Etapa 3 Realizar la suma, quitar el signo de la mantissa y codificar el corrimiento hacia la izquierda. 
260 97 jguarin200
        --adder:sadd2
261
        --port map (s3sma(24)&s3sma,s3smb(24)&s3smb,dpc,s3res);
262 98 jguarin200
        process (s3sma,s3smb)
263 97 jguarin200
        begin
264 98 jguarin200
                --! Magia: La suma ocurre aqui
265
                s3res <= (s3sma(24)&s3sma)+(s3smb(24)&s3smb);
266 97 jguarin200
        end process;
267 95 jguarin200
        process(s3res)
268
                variable lshift : integer range 24 downto 0;
269 93 jguarin200
        begin
270 95 jguarin200
                lshift:=24;
271
 
272 93 jguarin200
                for i in 0 to 23 loop
273 95 jguarin200
                        s3ures(i) <= s3res(25) xor s3res(i);
274
                        if (s3res(25) xor s3res(i))='1' then
275 93 jguarin200
                                lshift:=23-i;
276
                        end if;
277
                end loop;
278 95 jguarin200
                s3ures(24) <= s3res(24) xor s3res(25);
279
                s3lshift <= conv_std_logic_vector(lshift,5);
280 93 jguarin200
        end process;
281 95 jguarin200
        --! Combinatorial Gremlin, Etapa 4 corrimientos y normalizaci&oacute;n de la mantissa resultado.
282
        normsupershiftermult:lpm_mult
283
        generic map ("DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9","UNSIGNED","LPM_MULT",9,9,18)
284
        port    map (shl(conv_std_logic_vector(1,9),s4lshift(2 downto 0)),s4ures(22 downto 14),s4nrmS);
285
        normhighshiftermult:lpm_mult
286
        generic map ("DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9","UNSIGNED","LPM_MULT",9,9,18)
287
        port    map (shl(conv_std_logic_vector(1,9),s4lshift(2 downto 0)),s4ures(13 downto 5),s4nrmH);
288
        normlowshiftermult:lpm_mult
289
        generic map ("DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9","UNSIGNED","LPM_MULT",9,9,18)
290
        port    map (shl(conv_std_logic_vector(1,9),s4lshift(2 downto 0)),s4ures(4 downto 0)&conv_std_logic_vector(0,4),s4nrmL);
291
        process (s4nrmS,s4nrmH,s4nrmL)
292
        begin
293
                s4nrmP(22 downto 14) <= s4nrmS(8 downto 0) or s4nrmH(17 downto 9);
294
                s4nrmP(13 downto 5) <= s4nrmH(8 downto 0) or s4nrmL(17 downto 9);
295
                s4nrmP(4 downto 0) <= s4nrmL(8 downto 4);
296
        end process;
297
        s4signslab:
298
        for i in 15 downto 0 generate
299
                s4slab(i) <= '0';
300
        end generate s4signslab;
301 102 jguarin200
end ema32x2_arch;
302 84 jguarin200
 
303
 

powered by: WebSVN 2.1.0

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