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

Subversion Repositories raytrac

[/] [raytrac/] [branches/] [fp_sgdma/] [arith/] [single/] [fadd32long.vhd] - Blame information for rev 238

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 118 jguarin200
------------------------------------------------
2 119 jguarin200
--! @file fadd32.vhd
3 118 jguarin200
--! @brief RayTrac Floating Point Adder  
4
--! @author Julián Andrés Guarín Reyes
5
--------------------------------------------------
6
 
7
 
8
-- RAYTRAC (FP BRANCH)
9
-- Author Julian Andres Guarin
10 119 jguarin200
-- fadd32.vhd
11 118 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
library ieee;
26
use ieee.std_logic_1164.all;
27
use ieee.std_logic_unsigned.all;
28 228 jguarin200
 
29 155 jguarin200
use work.arithpack.all;
30
 
31 118 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. 
32
--!\nLas 2 mantissas y el exponente entran despues a la entidad add2 que suma las mantissas y entrega el resultado en formato IEEE 754.
33 227 jguarin200
entity fadd32long is
34 150 jguarin200
 
35 118 jguarin200
        port (
36 150 jguarin200
                clk,dpc : in std_logic;
37 229 jguarin200
                a32,b32 : in std_logic_vector(31 downto 0);
38
                c32             : out std_logic_vector(31 downto 0)
39 118 jguarin200
        );
40 153 jguarin200
end entity;
41 230 jguarin200
architecture fadd32long_arch of fadd32long is
42 118 jguarin200
 
43 228 jguarin200
        --! Altera Compiler Directive, to avoid m9k autoinferring thanks to the guys at http://www.alteraforum.com/forum/archive/index.php/t-30784.html .... 
44 230 jguarin200
        attribute altera_attribute : string;
45
        attribute altera_attribute of fadd32long_arch : architecture is "-name AUTO_SHIFT_REGISTER_RECOGNITION OFF";
46 118 jguarin200
 
47 163 jguarin200
        --!TBXSTART:STAGE0
48 227 jguarin200
        signal s0delta  : std_logic_vector(8 downto 0);
49 163 jguarin200
        signal s0a,s0b  : std_logic_vector(31 downto 0); -- Float 32 bit 
50
 
51 152 jguarin200
        --!TBXEND
52 163 jguarin200
        --!TBXSTART:STAGE1
53
        signal s1zero                                                                                   : std_logic;
54
        signal s1delta                                                                                  : std_logic_vector(5 downto 0);
55
        signal s1exp                                                                                    : std_logic_vector(7 downto 0);
56
        signal s1shifter,s1datab_8x                                                             : std_logic_vector(8 downto 0);
57
        signal s1pl,s1datab                                                                             : std_logic_vector(17 downto 0);
58
        signal s1umantshift,s1umantfixed,s1postshift,s1xorslab  : std_logic_vector(23 downto 0);
59
        signal s1ph                                                                                             : std_logic_vector(26 downto 0);
60
        --!TBXEND
61
        --!TBXSTART:STAGE2
62
        signal s2exp                                            : std_logic_vector(7 downto 0);
63
        signal s2xorslab                                        : std_logic_vector(23 downto 0);
64
        signal s2umantshift, s2mantfixed        : std_logic_vector(24 downto 0);
65
        --!TBXEND
66
        --!TBXSTART:STAGE3
67
        signal s3exp                                    : std_logic_vector(7 downto 0);
68
        signal s3mantfixed,s3mantshift  : std_logic_vector (24 downto 0);
69
        --!TBXEND
70
        --!TBXSTART:STAGE4
71
        signal s4exp            : std_logic_vector (7 downto 0);
72
        signal s4xorslab        : std_logic_vector (24 downto 0);
73
        signal s4sresult                : std_logic_vector (25 downto 0);
74
        --!TBXEND
75
        --!TBXSTART:STAGE5
76
        signal s5tokena,s5tokenb,s5tokenc       : std_logic;
77
        signal s5token                                          : std_logic_vector (2 downto 0);
78
        signal s5exp,s5factor                           : std_logic_vector (7 downto 0);
79
        signal s5factorhot9                                     : std_logic_vector (8 downto 0);
80
        signal s5factorhot24                            : std_logic_vector (23 downto 0);
81
        signal s5result                                         : std_logic_vector (25 downto 0);
82
        --!TBXEND
83
        --!TBXSTART:STAGE6
84
        signal s6exp,s6factor                   : std_logic_vector(7 downto 0);
85
        signal s6factorhot9,s6datab_4x  : std_logic_vector(8 downto 0);
86
        signal s6pl,s6datab                             : std_logic_vector(17 downto 0);
87
        signal s6postshift                              : std_logic_vector(22 downto 0);
88
        signal s6result                                 : std_logic_vector(25 downto 0); -- Signed mantissa result
89
        signal s6ph                                             : std_logic_vector(26 downto 0);
90
        --!TBXEND
91
        --!TBXSTART:STAGE7
92
        signal s7sign                                   : std_logic;
93
        signal s7exp,s7factor                   : std_logic_vector(7 downto 0);
94
        signal s7postshift                              : std_logic_vector(22 downto 0);
95
        --!TBXEND
96 118 jguarin200
 
97 163 jguarin200
 
98 228 jguarin200
        --! LPM_MULTIPLIER
99
        component lpm_mult
100
        generic (
101
                lpm_hint                        : string;
102
                lpm_pipeline            : natural;
103
                lpm_representation      : string;
104
                lpm_type                        : string;
105
                lpm_widtha                      : natural;
106
                lpm_widthb                      : natural;
107
                lpm_widthp                      : natural
108
        );
109
        port (
110
                dataa   : in std_logic_vector ( lpm_widtha-1 downto 0 );
111
                datab   : in std_logic_vector ( lpm_widthb-1 downto 0 );
112
                result  : out std_logic_vector( lpm_widthp-1 downto 0 )
113
        );
114
        end component;
115 163 jguarin200
 
116
 
117 118 jguarin200
begin
118 150 jguarin200
 
119 139 jguarin200
        process (clk)
120 118 jguarin200
        begin
121 139 jguarin200
                if clk'event and clk='1'  then
122 118 jguarin200
 
123 227 jguarin200
                        --! Debug Register.
124
                        --! datab <= s1zero&"000"&x"00000"&s0b(30 downto 23);
125
                        --! datab <= x"00"&s1exp&s0a(30 downto 23)&s0b(30 downto 23);
126
 
127 118 jguarin200
                        --!Registro de entrada
128
                        s0a <= a32;
129
                        s0b(31) <= dpc xor b32(31);     --! Importante: Integrar el signo en el operando B
130
                        s0b(30 downto 0) <= b32(30 downto 0);
131
 
132
                        --!Etapa 0,Escoger el mayor exponente que sera el resultado desnormalizado, calcula cuanto debe ser el corrimiento de la mantissa con menor exponente y reorganiza los operandos, si el mayor es b, intercambia las posici&oacute;n si el mayor es a las posiciones la mantiene. Zero check.
133
                        --!signo,exponente,mantissa
134 227 jguarin200
 
135
 
136
                        s1delta <= s0delta(8) & (s0delta(8) xor s0delta(4))&(s0delta(8) xor s0delta(3)) & s0delta(2 downto 0);
137
                        if s0delta(8)='1' then
138
 
139
                                s1exp <= s0b(30 downto 23);
140
                                s1umantshift <= s0a(31)&s0a(22 downto 0);
141
                                s1umantfixed <= s0b(31)&s0b(22 downto 0);
142
                                if s0a(30 downto 23)=x"00" then
143
                                        s1zero <= '0';
144
                                else
145
                                        s1zero <= '1';
146
                                end if;
147 118 jguarin200
                        else
148 227 jguarin200
                                if s0b(30 downto 23)=x"00" then
149
                                        s1zero <= '0';
150
                                else
151
                                        s1zero <= '1';
152
                                end if;
153
                                s1exp <= s0a(30 downto 23);
154
                                s1umantshift <= s0b(31)&s0b(22 downto 0);
155
                                s1umantfixed <= s0a(31)&s0a(22 downto 0);
156 118 jguarin200
                        end if;
157 164 jguarin200
                        --! Etapa 1: Denormalizaci&oacute;n de la mantissas.
158 118 jguarin200
                        case s1delta(4 downto 3) is
159
                                when "00" =>    s2umantshift <= s1umantshift(23)&s1postshift(23 downto 0);
160
                                when "01" =>    s2umantshift <= s1umantshift(23)&x"00"&s1postshift(23 downto 8);
161
                                when "10" =>    s2umantshift <= s1umantshift(23)&x"0000"&s1postshift(23 downto 16);
162
                                when others =>  s2umantshift <= (others => '0');
163
                        end case;
164 164 jguarin200
 
165
                        s2mantfixed <= s1umantfixed(23) & ( ( ('1'&s1umantfixed(22 downto 0)) xor s1xorslab) + ( x"00000"&"000"&s1umantfixed(23)  )   );
166 118 jguarin200
                        s2exp  <= s1exp;
167
 
168
                        --! Etapa2: Signar la mantissa denormalizada.
169
                        s3mantfixed <= s2mantfixed;
170
                        s3mantshift <= s2umantshift(24)&         (  (      s2umantshift(23 downto 0)  xor s2xorslab)   + ( x"00000"&"000"&s2umantshift(24)  )   );
171
                        s3exp           <= s2exp;
172
 
173 119 jguarin200
                        --! Etapa 3: Etapa 3 Realizar la suma, entre la mantissa corrida y la fija.
174 118 jguarin200
                        s4sresult       <= (s3mantshift(24)&s3mantshift)+(s3mantfixed(24)&s3mantfixed);
175
                        s4exp           <= s3exp;
176
 
177
                        --! Etapa 4: Quitar el signo a la mantissa resultante.
178
                        s5result        <= s4sresult(25)&((s4sresult(24 downto 0) xor s4xorslab)  +(x"000000"&s4sresult(25)));
179
                        s5exp           <= s4exp;
180
 
181
 
182
                        --! Etapa 5: Codificar el corrimiento para la normalizacion de la mantissa resultante.
183 119 jguarin200
                        s6result                <= s5result;
184
                        s6exp                   <= s5exp;
185 118 jguarin200
                        s6factor                <= s5factor;
186 119 jguarin200
                        s6factorhot9    <= s5factorhot9;
187 118 jguarin200
 
188 119 jguarin200
                        --! Etapa 6: Ejecutar el corrimiento de la mantissa.
189 120 jguarin200
                        s7sign                  <= s6result(25);
190 119 jguarin200
                        s7exp                   <= s6exp;
191 166 jguarin200
                        s7factor                <= not(s6factor)+1;
192 119 jguarin200
                        s7postshift             <= s6postshift;
193
 
194 137 jguarin200
 
195 118 jguarin200
                end if;
196
        end process;
197 137 jguarin200
 
198
        --! Etapa 7: Entregar el resultado.
199
        c32(31) <= s7sign;
200
        process(s7exp,s7postshift,s7factor)
201
        begin
202
                c32(30 downto 23)       <= s7exp+s7factor;
203
                case s7factor(4 downto 3) is
204
                        when "01"       => c32(22 downto 0) <= s7postshift(14 downto 00)&x"00";
205
                        when "10"       => c32(22 downto 0) <= s7postshift(06 downto 00)&x"0000";
206
                        when others => c32(22 downto 0)  <= s7postshift;
207
                end case;
208
        end process;
209 118 jguarin200
        --! Combinatorial gremlin, Etapa 0 el corrimiento de la mantissa con menor exponente y reorganiza los operandos,\n
210
        --! si el mayor es b, intercambia las posici&oacute;n si el mayor es a las posiciones la mantiene. 
211 227 jguarin200
        s0delta <=  ('0'&s0a(30 downto 23))-('0'&s0b(30 downto 23));
212 118 jguarin200
        --! Combinatorial Gremlin, Etapa 1 Codificar el factor de corrimiento de denormalizacion y denormalizar la mantissa no fija. Signar la mantissa que se queda fija.
213
        decodeshiftfactor:
214
        process (s1delta(2 downto 0))
215
        begin
216
                case s1delta(2 downto 0) is
217
                        when "111" =>  s1shifter(8 downto 0) <= '0'&s1delta(5)&"00000"&not(s1delta(5))&'0';
218
                        when "110" =>  s1shifter(8 downto 0) <= "00"&s1delta(5)&"000"&not(s1delta(5))&"00";
219
                        when "101" =>  s1shifter(8 downto 0) <= "000"&s1delta(5)&'0'&not(s1delta(5))&"000";
220
                        when "100" =>  s1shifter(8 downto 0) <= '0'&x"10";
221
                        when "011" =>  s1shifter(8 downto 0) <= "000"&not(s1delta(5))&'0'&s1delta(5)&"000";
222
                        when "010" =>  s1shifter(8 downto 0) <= "00"&not(s1delta(5))&"000"&s1delta(5)&"00";
223
                        when "001" =>  s1shifter(8 downto 0) <= '0'&not(s1delta(5))&"00000"&s1delta(5)&'0';
224
                        when others => s1shifter(8 downto 0) <=    not(s1delta(5))&"0000000"&s1delta(5);
225
                end case;
226
        end process;
227 157 jguarin200
        s1datab <= s1zero&s1umantshift(22 downto 06);
228 118 jguarin200
        denormhighshiftermult:lpm_mult
229 155 jguarin200
        generic map (
230
                lpm_hint => "DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9",
231
                lpm_pipeline => 0,
232
                lpm_representation => "UNSIGNED",
233
                lpm_type => "LPM_MULT",
234
                lpm_widtha => 9,
235
                lpm_widthb => 18,
236
                lpm_widthp => 27
237
        )
238
        port map (
239
                dataa => s1shifter,
240 157 jguarin200
                datab => s1datab,
241 155 jguarin200
                result => s1ph
242
        );
243 157 jguarin200
        s1datab_8x <= s1umantshift(5 downto 0)&"000";
244 118 jguarin200
        denormlowshiftermult:lpm_mult
245 155 jguarin200
        generic map (
246
                lpm_hint => "DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9",
247
                lpm_pipeline => 0,
248
                lpm_representation => "UNSIGNED",
249
                lpm_type => "LPM_MULT",
250
                lpm_widtha => 9,
251
                lpm_widthb => 9,
252
                lpm_widthp => 18
253
        )
254
        port map (
255
                dataa => s1shifter,
256 157 jguarin200
                datab(8 downto 0) => s1datab_8x,
257 155 jguarin200
                result => s1pl
258
        );
259 118 jguarin200
 
260
        s1postshift(23 downto 7) <= s1ph(25 downto 9);
261
        s1postshift(06 downto 0) <= s1ph(08 downto 2) or s1pl(17 downto 11);
262
        s1xorslab(23 downto 0) <= (others => s1umantfixed(23));
263
 
264
        --! Combinatorial Gremlin, Etapa 2: Signar la mantissa denormalizada. 
265
        s2xorslab <= (others => s2umantshift(24));
266
 
267
        --! Combinatorial Gremlin, Etapa 4: Quitar el signo de la mantissa resultante.
268
        s4xorslab <= (others => s4sresult(25));
269
 
270
        --! Combinatorial Gremlin, Etapa 5: Codificar el factor de normalizacion de la mantissa resultante.
271
        normalizerdecodeshift:
272 120 jguarin200
        process (s5result,s5factorhot24,s5token,s5tokena,s5tokenb,s5tokenc,s5factorhot9)
273 118 jguarin200
        begin
274 120 jguarin200
                s5tokena <= not(s5result(24));
275
                s5tokenb <= not(s5result(24));
276
                s5tokenc <= not(s5result(24));
277
                s5factor(7 downto 5) <= (others => s5result(24));
278
                s5factorhot24 <= x"000000";
279
                for i in 23 downto 16 loop
280 118 jguarin200
                        if s5result(i)='1' then
281 120 jguarin200
                                s5factorhot24(23-i) <= s5tokena;
282
                                s5tokenb <= '0';
283
                                s5tokenc <= '0';
284 118 jguarin200
                                exit;
285
                        end if;
286
                end loop;
287 120 jguarin200
                for i in 15 downto 8 loop
288
                        if s5result(i)='1' then
289
                                s5factorhot24(23-i) <= s5tokenb;
290
                                s5tokenc <= '0';
291
                                exit;
292
                        end if;
293
                end loop;
294
                for i in 7 downto 0 loop
295
                        if s5result(i)='1' then
296
                                s5factorhot24(23-i) <= s5tokenc;
297
                                exit;
298
                        end if;
299
                end loop;
300
                s5token <=s5tokena&s5tokenb&s5tokenc;
301
                case (s5token) is
302 165 jguarin200
                        when "100"  => s5factor(4 downto 3) <= "00";
303 120 jguarin200
                        when "110"  => s5factor(4 downto 3) <= "01";
304 165 jguarin200
                        when "111"      => s5factor(4 downto 3) <= "10";
305 120 jguarin200
                        when others => s5factor(4 downto 3) <= (others => s5result(24));
306
                end case;
307
                s5factorhot9 <= (s5factorhot24(7 downto 0)or s5factorhot24(15 downto 8)or s5factorhot24(23 downto 16)) & s5result(24);
308
                case s5factorhot9 is
309
                        when "100000000" => s5factor(2 downto 0) <= "111";
310
                        when "010000000" => s5factor(2 downto 0) <= "110";
311
                        when "001000000" => s5factor(2 downto 0) <= "101";
312
                        when "000100000" => s5factor(2 downto 0) <= "100";
313
                        when "000010000" => s5factor(2 downto 0) <= "011";
314
                        when "000001000" => s5factor(2 downto 0) <= "010";
315
                        when "000000100" => s5factor(2 downto 0) <= "001";
316
                        when "000000010" => s5factor(2 downto 0) <= "000";
317
                        when others => s5factor (2 downto 0) <= (others => s5result(24));
318
                end case;
319
 
320 118 jguarin200
        end process;
321 119 jguarin200
 
322
        --! Etapa 6: Ejecutar el corrimiento para normalizar la mantissa.
323 157 jguarin200
        s6datab <= s6result(24 downto 7);
324 118 jguarin200
        normhighshiftermult:lpm_mult
325 155 jguarin200
        generic map (
326
                lpm_hint => "DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9",
327
                lpm_pipeline => 0,
328
                lpm_representation => "UNSIGNED",
329
                lpm_type => "LPM_MULT",
330
                lpm_widtha => 9,
331
                lpm_widthb => 18,
332
                lpm_widthp => 27
333
        )
334
        port map (
335
                dataa => s6factorhot9,
336 157 jguarin200
                datab => s6datab,
337 155 jguarin200
                result => s6ph
338
        );
339 157 jguarin200
        s6datab_4x <= s6result(06 downto 0)&"00";
340 118 jguarin200
        normlowshiftermult:lpm_mult
341 155 jguarin200
        generic map (
342
                lpm_hint => "DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9",
343
                lpm_pipeline => 0,
344
                lpm_representation => "UNSIGNED",
345
                lpm_type => "LPM_MULT",
346
                lpm_widtha => 9,
347
                lpm_widthb => 9,
348
                lpm_widthp => 18
349
        )
350
        port map (
351
                dataa => s6factorhot9,
352 157 jguarin200
                datab => s6datab_4x,
353 155 jguarin200
                result => s6pl
354
        );
355 119 jguarin200
        s6postshift(22 downto 15) <= s6ph(16 downto 09);
356 120 jguarin200
        s6postshift(14 downto 06) <= s6ph(08 downto 00) + s6pl(17 downto 09);
357 119 jguarin200
        s6postshift(05 downto 00) <= s6pl(08 downto 03);
358 118 jguarin200
 
359
 
360
 
361
 
362
 
363 153 jguarin200
end architecture;
364 118 jguarin200
 
365
 

powered by: WebSVN 2.1.0

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