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

Subversion Repositories raytrac

[/] [raytrac/] [branches/] [fp/] [fadd32.vhd] - Blame information for rev 155

Go to most recent revision | 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 155 jguarin200
 
29
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 139 jguarin200
entity fadd32 is
34 150 jguarin200
 
35 118 jguarin200
        port (
36 150 jguarin200
                clk,dpc : in std_logic;
37
                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 119 jguarin200
architecture fadd32_arch of fadd32 is
42 118 jguarin200
 
43
 
44 155 jguarin200
 
45 152 jguarin200
        signal s1zero,s7sign                                                                                    : std_logic;
46
        --!TBXSTART:STAGE5
47 120 jguarin200
        signal s5token                                                                                                                                          : std_logic_vector(2 downto 0);
48 152 jguarin200
        signal s5tokena,s5tokenb,s5tokenc                                                                                                       : std_logic;
49
        --!TBXEND
50 119 jguarin200
        signal s1delta                                                                                                                                          : std_logic_vector(5 downto 0);
51
        signal s0delta,s1exp,s2exp,s3exp,s4exp,s5exp,s6exp,s5factor,s6factor,s7exp,s7factor     : std_logic_vector(7 downto 0);
52
        signal s1shifter,s5factorhot9,s6factorhot9                                                                                      : std_logic_vector(8 downto 0);
53
        signal s1pl,s6pl                                                                                                                                        : std_logic_vector(17 downto 0);
54
        signal s6postshift,s7postshift                                                                                                          : std_logic_vector(22 downto 0);
55
        signal s1umantshift,s1umantfixed,s1postshift,s1xorslab,s2xorslab                                        : std_logic_vector(23 downto 0);
56 120 jguarin200
        signal s5factorhot24                                                                                                                            : std_logic_vector(23 downto 0);
57 119 jguarin200
        signal s2umantshift,s2mantfixed,s3mantfixed,s3mantshift,s4xorslab                                       : std_logic_vector(24 downto 0);
58 120 jguarin200
        signal s4sresult,s5result,s6result                                                                                                      : std_logic_vector(25 downto 0); -- Signed mantissa result
59 119 jguarin200
        signal s1ph,s6ph                                                                                                                                        : std_logic_vector(26 downto 0);
60
        signal s0a,s0b                                                                                                                                          : std_logic_vector(31 downto 0); -- Float 32 bit 
61 139 jguarin200
        signal sxprop : std_logic_vector(7 downto 0);
62 118 jguarin200
 
63
begin
64 150 jguarin200
 
65 139 jguarin200
        process (clk)
66 118 jguarin200
        begin
67 139 jguarin200
                if clk'event and clk='1'  then
68 118 jguarin200
 
69
                        --!Registro de entrada
70
                        s0a <= a32;
71
                        s0b(31) <= dpc xor b32(31);     --! Importante: Integrar el signo en el operando B
72
                        s0b(30 downto 0) <= b32(30 downto 0);
73
 
74
                        --!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.
75
                        --!signo,exponente,mantissa
76
                        if (s0b(30 downto 23)&s0a(30 downto 23))=x"0000" then
77
                                s1zero <= '0';
78
                        else
79
                                s1zero <= '1';
80
                        end if;
81 119 jguarin200
                        s1delta <= s0delta(7) & (s0delta(7) xor s0delta(4))&(s0delta(7) xor s0delta(3)) & s0delta(2 downto 0);
82 118 jguarin200
                        case s0delta(7) is
83
                                when '1'  =>
84
                                        s1exp <= s0b(30 downto 23);
85
                                        s1umantshift <= s0a(31)&s0a(22 downto 0);
86
                                        s1umantfixed <= s0b(31)&s0b(22 downto 0);
87
                                when others =>
88
                                        s1exp <= s0a(30 downto 23);
89
                                        s1umantshift <= s0b(31)&s0b(22 downto 0);
90
                                        s1umantfixed <= s0a(31)&s0a(22 downto 0);
91
                        end case;
92
 
93
                        --! Etapa 1: Denormalizaci&oacute;n de la mantissas.  
94
                        case s1delta(4 downto 3) is
95
                                when "00" =>    s2umantshift <= s1umantshift(23)&s1postshift(23 downto 0);
96
                                when "01" =>    s2umantshift <= s1umantshift(23)&x"00"&s1postshift(23 downto 8);
97
                                when "10" =>    s2umantshift <= s1umantshift(23)&x"0000"&s1postshift(23 downto 16);
98
                                when others =>  s2umantshift <= (others => '0');
99
                        end case;
100
                        s2mantfixed <= s1umantfixed(23) &         ( ( ('1'&s1umantfixed(22 downto 0)) xor s1xorslab)   + ( x"00000"&"000"&s1umantfixed(23)  )   );
101
                        s2exp  <= s1exp;
102
 
103
                        --! Etapa2: Signar la mantissa denormalizada.
104
                        s3mantfixed <= s2mantfixed;
105
                        s3mantshift <= s2umantshift(24)&         (  (      s2umantshift(23 downto 0)  xor s2xorslab)   + ( x"00000"&"000"&s2umantshift(24)  )   );
106
                        s3exp           <= s2exp;
107
 
108 119 jguarin200
                        --! Etapa 3: Etapa 3 Realizar la suma, entre la mantissa corrida y la fija.
109 118 jguarin200
                        s4sresult       <= (s3mantshift(24)&s3mantshift)+(s3mantfixed(24)&s3mantfixed);
110
                        s4exp           <= s3exp;
111
 
112
                        --! Etapa 4: Quitar el signo a la mantissa resultante.
113
                        s5result        <= s4sresult(25)&((s4sresult(24 downto 0) xor s4xorslab)  +(x"000000"&s4sresult(25)));
114
                        s5exp           <= s4exp;
115
 
116
 
117
                        --! Etapa 5: Codificar el corrimiento para la normalizacion de la mantissa resultante.
118 119 jguarin200
                        s6result                <= s5result;
119
                        s6exp                   <= s5exp;
120 118 jguarin200
                        s6factor                <= s5factor;
121 119 jguarin200
                        s6factorhot9    <= s5factorhot9;
122 118 jguarin200
 
123 119 jguarin200
                        --! Etapa 6: Ejecutar el corrimiento de la mantissa.
124 120 jguarin200
                        s7sign                  <= s6result(25);
125 119 jguarin200
                        s7exp                   <= s6exp;
126 120 jguarin200
                        s7factor                <= s6factor;
127 119 jguarin200
                        s7postshift             <= s6postshift;
128
 
129 137 jguarin200
 
130 118 jguarin200
                end if;
131
        end process;
132 137 jguarin200
 
133
        --! Etapa 7: Entregar el resultado.
134
        c32(31) <= s7sign;
135
        process(s7exp,s7postshift,s7factor)
136
        begin
137
                c32(30 downto 23)       <= s7exp+s7factor;
138
                case s7factor(4 downto 3) is
139
                        when "01"       => c32(22 downto 0) <= s7postshift(14 downto 00)&x"00";
140
                        when "10"       => c32(22 downto 0) <= s7postshift(06 downto 00)&x"0000";
141
                        when others => c32(22 downto 0)  <= s7postshift;
142
                end case;
143
        end process;
144 118 jguarin200
        --! Combinatorial gremlin, Etapa 0 el corrimiento de la mantissa con menor exponente y reorganiza los operandos,\n
145
        --! si el mayor es b, intercambia las posici&oacute;n si el mayor es a las posiciones la mantiene. 
146
        s0delta <=  s0a(30 downto 23)-s0b(30 downto 23);
147
        --! Combinatorial Gremlin, Etapa 1 Codificar el factor de corrimiento de denormalizacion y denormalizar la mantissa no fija. Signar la mantissa que se queda fija.
148
        decodeshiftfactor:
149
        process (s1delta(2 downto 0))
150
        begin
151
                case s1delta(2 downto 0) is
152
                        when "111" =>  s1shifter(8 downto 0) <= '0'&s1delta(5)&"00000"&not(s1delta(5))&'0';
153
                        when "110" =>  s1shifter(8 downto 0) <= "00"&s1delta(5)&"000"&not(s1delta(5))&"00";
154
                        when "101" =>  s1shifter(8 downto 0) <= "000"&s1delta(5)&'0'&not(s1delta(5))&"000";
155
                        when "100" =>  s1shifter(8 downto 0) <= '0'&x"10";
156
                        when "011" =>  s1shifter(8 downto 0) <= "000"&not(s1delta(5))&'0'&s1delta(5)&"000";
157
                        when "010" =>  s1shifter(8 downto 0) <= "00"&not(s1delta(5))&"000"&s1delta(5)&"00";
158
                        when "001" =>  s1shifter(8 downto 0) <= '0'&not(s1delta(5))&"00000"&s1delta(5)&'0';
159
                        when others => s1shifter(8 downto 0) <=    not(s1delta(5))&"0000000"&s1delta(5);
160
                end case;
161
        end process;
162
        denormhighshiftermult:lpm_mult
163 155 jguarin200
        generic map (
164
                lpm_hint => "DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9",
165
                lpm_pipeline => 0,
166
                lpm_representation => "UNSIGNED",
167
                lpm_type => "LPM_MULT",
168
                lpm_widtha => 9,
169
                lpm_widthb => 18,
170
                lpm_widthp => 27
171
        )
172
        port map (
173
                dataa => s1shifter,
174
                datab => s1zero&s1umantshift(22 downto 06),
175
                result => s1ph
176
        );
177 118 jguarin200
        denormlowshiftermult:lpm_mult
178 155 jguarin200
        generic map (
179
                lpm_hint => "DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9",
180
                lpm_pipeline => 0,
181
                lpm_representation => "UNSIGNED",
182
                lpm_type => "LPM_MULT",
183
                lpm_widtha => 9,
184
                lpm_widthb => 9,
185
                lpm_widthp => 18
186
        )
187
        port map (
188
                dataa => s1shifter,
189
                datab => s1umantshift(5 downto 0)&"000",
190
                result => s1pl
191
        );
192 118 jguarin200
 
193
        s1postshift(23 downto 7) <= s1ph(25 downto 9);
194
        s1postshift(06 downto 0) <= s1ph(08 downto 2) or s1pl(17 downto 11);
195
        s1xorslab(23 downto 0) <= (others => s1umantfixed(23));
196
 
197
        --! Combinatorial Gremlin, Etapa 2: Signar la mantissa denormalizada. 
198
        s2xorslab <= (others => s2umantshift(24));
199
 
200
        --! Combinatorial Gremlin, Etapa 4: Quitar el signo de la mantissa resultante.
201
        s4xorslab <= (others => s4sresult(25));
202
 
203
        --! Combinatorial Gremlin, Etapa 5: Codificar el factor de normalizacion de la mantissa resultante.
204
        normalizerdecodeshift:
205 120 jguarin200
        process (s5result,s5factorhot24,s5token,s5tokena,s5tokenb,s5tokenc,s5factorhot9)
206 118 jguarin200
        begin
207 120 jguarin200
                s5tokena <= not(s5result(24));
208
                s5tokenb <= not(s5result(24));
209
                s5tokenc <= not(s5result(24));
210
                s5factor(7 downto 5) <= (others => s5result(24));
211
                s5factorhot24 <= x"000000";
212
                for i in 23 downto 16 loop
213 118 jguarin200
                        if s5result(i)='1' then
214 120 jguarin200
                                s5factorhot24(23-i) <= s5tokena;
215
                                s5tokenb <= '0';
216
                                s5tokenc <= '0';
217 118 jguarin200
                                exit;
218
                        end if;
219
                end loop;
220 120 jguarin200
                for i in 15 downto 8 loop
221
                        if s5result(i)='1' then
222
                                s5factorhot24(23-i) <= s5tokenb;
223
                                s5tokenc <= '0';
224
                                exit;
225
                        end if;
226
                end loop;
227
                for i in 7 downto 0 loop
228
                        if s5result(i)='1' then
229
                                s5factorhot24(23-i) <= s5tokenc;
230
                                exit;
231
                        end if;
232
                end loop;
233
                s5token <=s5tokena&s5tokenb&s5tokenc;
234
                case (s5token) is
235
                        when "100"  => s5factor(4 downto 3) <= "10";
236
                        when "110"  => s5factor(4 downto 3) <= "01";
237
                        when "111"      => s5factor(4 downto 3) <= "00";
238
                        when others => s5factor(4 downto 3) <= (others => s5result(24));
239
                end case;
240
                s5factorhot9 <= (s5factorhot24(7 downto 0)or s5factorhot24(15 downto 8)or s5factorhot24(23 downto 16)) & s5result(24);
241
                case s5factorhot9 is
242
                        when "100000000" => s5factor(2 downto 0) <= "111";
243
                        when "010000000" => s5factor(2 downto 0) <= "110";
244
                        when "001000000" => s5factor(2 downto 0) <= "101";
245
                        when "000100000" => s5factor(2 downto 0) <= "100";
246
                        when "000010000" => s5factor(2 downto 0) <= "011";
247
                        when "000001000" => s5factor(2 downto 0) <= "010";
248
                        when "000000100" => s5factor(2 downto 0) <= "001";
249
                        when "000000010" => s5factor(2 downto 0) <= "000";
250
                        when others => s5factor (2 downto 0) <= (others => s5result(24));
251
                end case;
252
 
253 118 jguarin200
        end process;
254 119 jguarin200
 
255
        --! Etapa 6: Ejecutar el corrimiento para normalizar la mantissa.
256 118 jguarin200
        normhighshiftermult:lpm_mult
257 155 jguarin200
        generic map (
258
                lpm_hint => "DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9",
259
                lpm_pipeline => 0,
260
                lpm_representation => "UNSIGNED",
261
                lpm_type => "LPM_MULT",
262
                lpm_widtha => 9,
263
                lpm_widthb => 18,
264
                lpm_widthp => 27
265
        )
266
        port map (
267
                dataa => s6factorhot9,
268
                datab => s6result(24 downto 7),
269
                result => s6ph
270
        );
271 118 jguarin200
        normlowshiftermult:lpm_mult
272 155 jguarin200
        generic map (
273
                lpm_hint => "DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9",
274
                lpm_pipeline => 0,
275
                lpm_representation => "UNSIGNED",
276
                lpm_type => "LPM_MULT",
277
                lpm_widtha => 9,
278
                lpm_widthb => 9,
279
                lpm_widthp => 18
280
        )
281
        port map (
282
                dataa => s6factorhot9,
283
                datab => s6result(06 downto 0)&"00",
284
                result => s6pl
285
        );
286 119 jguarin200
        s6postshift(22 downto 15) <= s6ph(16 downto 09);
287 120 jguarin200
        s6postshift(14 downto 06) <= s6ph(08 downto 00) + s6pl(17 downto 09);
288 119 jguarin200
        s6postshift(05 downto 00) <= s6pl(08 downto 03);
289 118 jguarin200
 
290
 
291
 
292
 
293
 
294 153 jguarin200
end architecture;
295 118 jguarin200
 
296
 

powered by: WebSVN 2.1.0

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