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

Subversion Repositories raytrac

[/] [raytrac/] [branches/] [fp_sgdma/] [deprecated/] [fadd32.vhd] - Blame information for rev 244

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

powered by: WebSVN 2.1.0

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