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

Subversion Repositories raytrac

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

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 91 jguarin200
 
65 84 jguarin200
begin
66
 
67
        process (clk)
68
        begin
69
                if clk'event and clk='1' then
70
 
71
                        --!Registro de entrada
72 95 jguarin200
                        s0a <= a32;
73 106 jguarin200
 
74 98 jguarin200
                        s0b(31) <= dpc xor b32(31);     --! Importante: Integrar el signo en el operando B
75
                        s0b(30 downto 0) <= b32(30 downto 0);
76 106 jguarin200
                        s0b(22 downto 0) <= b32(22 downto 0);
77
 
78
                        --!Etapa 0,Calcular la manera en que se llevara a cabo la desnormalizacion
79
                        s1dira          <= s0sdelta(7);
80
                        s1dirb          <= not(s0sdelta(7));
81
                        s1uma           <= s0a(22 downto 0);
82
                        s1umb           <= s0b(22 downto 0);
83
                        if s0zeroa='0' or s0zerob='0' then
84
                                s1expb  <= s0b(30 downto 23) or s0a(30 downto 23);
85
                                s1udeltaa       <= "0000";
86
                                s1udeltab       <= "0000";
87 84 jguarin200
                        else
88 106 jguarin200
                                s1expb  <= s0b(30 downto 23);
89
                                s1udeltaa       <= s0udeltaa(3 downto 0);
90
                                s1udeltab       <= s1udeltab(3 downto 0);
91 84 jguarin200
                        end if;
92
 
93 106 jguarin200
                        s1zeroa         <= s0zeroa;
94
                        s1zerob         <= s0zerob;
95
 
96
 
97 95 jguarin200
                        --! Etapa 1: Denormalizaci&oacute;n de las mantissas.  
98
                        --! A
99
                        s2exp <= s1a(30 downto 23);
100
                        s2sma <= s1sma;
101 84 jguarin200
 
102 95 jguarin200
                        --! B
103
                        for i in 23 downto 15 loop
104
                                s2smb(i)        <= s1pL(23-i) xor s1b(31);
105 91 jguarin200
                        end loop;
106 95 jguarin200
                        for i in 14 downto 6 loop
107
                                s2smb(i)        <= (s1pH(14-i) or s1pL(14-i+9)) xor s1b(31);
108
                        end loop;
109
                        for i in 5 downto 0 loop
110
                                s2smb(i)        <= (s1pS(5-i) or s1pH(5-i+9)) xor s1b(31);
111 91 jguarin200
                        end loop;
112 95 jguarin200
 
113
                        if s1b(30 downto 28)>"000" then
114
                                s2slr <= "11";
115
                        else
116
                                s2slr <= s1b(27 downto 26);
117
                        end if;
118 91 jguarin200
 
119 95 jguarin200
                        s2smb(24) <= s1b(31);
120 91 jguarin200
 
121 95 jguarin200
                        --! Etapa2: Finalizar la denormalizaci&oacute;n de b.
122
                        --! A
123
                        s3sma <= s2sma;
124
                        s3exp <= s2exp;
125 93 jguarin200
 
126 95 jguarin200
                        --! B
127
                        case (s2slr) is
128
                                when "00" =>
129
                                        s3smb   <= s2smb(24 downto 0)+s2smb(24);
130
                                when "01" =>
131
                                        s3smb   <= ( s2slab(8 downto 0) & s2smb(23 downto 8) ) + s2smb(24);
132
                                when "10"  =>
133
                                        s3smb   <= ( s2slab(16 downto 0) & s2smb(23 downto 16)) + s2smb(24);
134
                                when others =>
135
                                        s3smb   <= (others => '0');
136
                        end case;
137
 
138 93 jguarin200
 
139 95 jguarin200
                        --! Etapa 3: Etapa 3 Realizar la suma, quitar el signo de la mantissa y codificar el corrimiento hacia la izquierda.
140
                        s4ures  <= s3ures+s3res(25);                            --Resultado no signado
141 98 jguarin200
                        s4sgr   <= s3res(25);                                           --Signo
142 95 jguarin200
                        s4exp   <= s3exp;                                                       --Exponente 
143
                        s4lshift <= s3lshift;                                           --Corrimiento hacia la izquierda. 
144
 
145
                        --! Etapa 4: Corrimiento y normalizaci&oacute;n de la mantissa resultado.
146
                        res32(31) <= s4sgr;
147
                        if s4ures(24)='1' then
148
                                res32(22 downto 0) <= s4ures(23 downto 1);
149
                                res32(30 downto 23) <= s4exp+1;
150 93 jguarin200
                        else
151 95 jguarin200
                                case s4lshift(4 downto 3) is
152
                                        when "00" =>
153
                                                res32(22 downto 0)       <= s4nrmP(22 downto 0);
154
                                                res32(30 downto 23) <= s4exp - s4lshift;
155
                                        when "01" =>
156
                                                res32(22 downto 0)       <= s4nrmP(14 downto 0)   & s4slab(7 downto 0);
157
                                                res32(30 downto 23) <= s4exp - s4lshift;
158
                                        when "10" =>
159
                                                res32(22 downto 0)       <= s4nrmP(6 downto 0)    & s4slab(15 downto 0);
160
                                                res32(30 downto 23) <= s4exp - s4lshift;
161
                                        when others =>
162
                                                res32(30 downto 0) <= (others => '0');
163
                                end case;
164
 
165 93 jguarin200
                        end if;
166
 
167 84 jguarin200
                end if;
168
        end process;
169 106 jguarin200
        --! Combinatorial gremlin, Etapa 0, Calcular la manera en que se llevara a cabo la desnormalizacion.
170 95 jguarin200
        process (s0b(30 downto 23),s0a(30 downto 23))
171 88 jguarin200
        begin
172 106 jguarin200
                --! Diferencia signada entre el valor del exponente a y el exponente b
173
                s0sdelta <= s0a(30 downto 23) - s0b(30 downto 23);
174
 
175
                --! Manejo de cero
176
                if sa(30 downto 23) = "00000000" then
177
                        s0zeroa <= '0';
178
                else
179
                        s0zeroa <= '1';
180
                end if;
181
 
182
                if sb(30 downto 23) = "00000000" then
183
                        s0zerob <= '0';
184
                else
185
                        s0zerob <= '1';
186
                end if;
187
 
188
 
189
        end process;
190
 
191
        process (s0sdelta)
192
        begin
193
                --! Esta parte define en que rango de la grafica de normalizac&oacute;n se movera la normalizaci—n del resultado de la mantissa
194
                case s0sdelta(7 downto 1) is
195
                        when "0000000" =>
196
                                s0nrmshftype <= '0';
197
                        when "1111111" =>
198
                                s0nrmshftype <= not(s0sdelta(0));
199
                        when others =>
200
                                s0nrmshftype <= '1';
201
                end case;
202
 
203
                --! Valor absoluto de la diferencia entre el exponente a y el b
204
                for i in 7 downto 0 loop
205
                        s0udelta(i) <= s0sdelta(7) xor s0sdelta(i);
206 88 jguarin200
                end loop;
207 106 jguarin200
 
208
 
209
        end process
210
 
211
        process (s0udelta,s0sdelta(7))
212
        begin
213
                s0udeltaa <= (s0udelta(7)&s0udelta(7 downto 1))+("0000000"&s0sdelta(7));
214
                s0udeltab <= (s0udelta(7)&s0udelta(7 downto 1))+("0000000"&s0udelta(0));
215 88 jguarin200
        end process;
216 95 jguarin200
 
217
 
218 106 jguarin200
        --! Combinatorial Gremlin, Etapa 1 Denormalizaci&oacute;n de las mantissas.
219
        shftra:shftr
220
        port    map (s1dira,s1udeltaa(2 downto 0),s1uma,
221
 
222 95 jguarin200
        s1b2b1s:
223 91 jguarin200
        for i in 22 downto 0 generate
224 95 jguarin200
                b1s(i) <= s1b(22-i);
225
        end generate s1b2b1s;
226
        signa:
227
        for i in 22 downto 0 generate
228
                s1sma(i) <= s1a(31) xor s1a(i);
229
        end generate;
230
        s1sma(23) <= not(s1a(31));
231
        s1sma(24) <= s1a(31);
232 84 jguarin200
 
233 93 jguarin200
 
234 95 jguarin200
        --! Combinatorial Gremlin, Etapa2: Finalizar la denormalizaci&oacute;n de b.
235
        s2signslab:
236
        for i in 16 downto 0 generate
237
                s2slab(i) <= s2smb(24);
238
        end generate s2signslab;
239
 
240
        --! Combinatorial Gremlin, Etapa 3 Realizar la suma, quitar el signo de la mantissa y codificar el corrimiento hacia la izquierda. 
241 97 jguarin200
        --adder:sadd2
242
        --port map (s3sma(24)&s3sma,s3smb(24)&s3smb,dpc,s3res);
243 98 jguarin200
        process (s3sma,s3smb)
244 97 jguarin200
        begin
245 98 jguarin200
                --! Magia: La suma ocurre aqui
246
                s3res <= (s3sma(24)&s3sma)+(s3smb(24)&s3smb);
247 97 jguarin200
        end process;
248
 
249 95 jguarin200
        process(s3res)
250
                variable lshift : integer range 24 downto 0;
251 93 jguarin200
        begin
252 95 jguarin200
                lshift:=24;
253
 
254 93 jguarin200
                for i in 0 to 23 loop
255 95 jguarin200
                        s3ures(i) <= s3res(25) xor s3res(i);
256
                        if (s3res(25) xor s3res(i))='1' then
257 93 jguarin200
                                lshift:=23-i;
258
                        end if;
259
                end loop;
260 95 jguarin200
                s3ures(24) <= s3res(24) xor s3res(25);
261
                s3lshift <= conv_std_logic_vector(lshift,5);
262 93 jguarin200
        end process;
263
 
264
 
265 95 jguarin200
        --! Combinatorial Gremlin, Etapa 4 corrimientos y normalizaci&oacute;n de la mantissa resultado.
266
        normsupershiftermult:lpm_mult
267
        generic map ("DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9","UNSIGNED","LPM_MULT",9,9,18)
268
        port    map (shl(conv_std_logic_vector(1,9),s4lshift(2 downto 0)),s4ures(22 downto 14),s4nrmS);
269
        normhighshiftermult:lpm_mult
270
        generic map ("DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9","UNSIGNED","LPM_MULT",9,9,18)
271
        port    map (shl(conv_std_logic_vector(1,9),s4lshift(2 downto 0)),s4ures(13 downto 5),s4nrmH);
272
        normlowshiftermult:lpm_mult
273
        generic map ("DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9","UNSIGNED","LPM_MULT",9,9,18)
274
        port    map (shl(conv_std_logic_vector(1,9),s4lshift(2 downto 0)),s4ures(4 downto 0)&conv_std_logic_vector(0,4),s4nrmL);
275
        process (s4nrmS,s4nrmH,s4nrmL)
276
        begin
277
                s4nrmP(22 downto 14) <= s4nrmS(8 downto 0) or s4nrmH(17 downto 9);
278
                s4nrmP(13 downto 5) <= s4nrmH(8 downto 0) or s4nrmL(17 downto 9);
279
                s4nrmP(4 downto 0) <= s4nrmL(8 downto 4);
280
        end process;
281
        s4signslab:
282
        for i in 15 downto 0 generate
283
                s4slab(i) <= '0';
284
        end generate s4signslab;
285 102 jguarin200
end ema32x2_arch;
286 84 jguarin200
 
287
 

powered by: WebSVN 2.1.0

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