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

Subversion Repositories raytrac

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

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

powered by: WebSVN 2.1.0

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