1 |
115 |
jguarin200 |
------------------------------------------------
|
2 |
|
|
--! @file ema32x2.vhd
|
3 |
|
|
--! @brief RayTrac Floating Point Adder
|
4 |
|
|
--! @author Julián Andrés Guarín Reyes
|
5 |
|
|
--------------------------------------------------
|
6 |
114 |
jguarin200 |
|
7 |
|
|
|
8 |
115 |
jguarin200 |
-- RAYTRAC (FP BRANCH)
|
9 |
|
|
-- Author Julian Andres Guarin
|
10 |
|
|
-- ema32x2.vhd
|
11 |
|
|
-- 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 |
114 |
jguarin200 |
|
26 |
106 |
jguarin200 |
library ieee;
|
27 |
|
|
use ieee.std_logic_1164.all;
|
28 |
108 |
jguarin200 |
use ieee.std_logic_unsigned.all;
|
29 |
114 |
jguarin200 |
use ieee.std_logic_arith.all;
|
30 |
106 |
jguarin200 |
|
31 |
|
|
|
32 |
115 |
jguarin200 |
--! Esta entidad recibe dos números 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 |
|
|
entity ema32x2 is
|
35 |
106 |
jguarin200 |
port (
|
36 |
115 |
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 |
106 |
jguarin200 |
);
|
40 |
115 |
jguarin200 |
end ema32x2;
|
41 |
106 |
jguarin200 |
|
42 |
115 |
jguarin200 |
architecture ema32x2_arch of ema32x2 is
|
43 |
|
|
|
44 |
106 |
jguarin200 |
component lpm_mult
|
45 |
|
|
generic (
|
46 |
|
|
lpm_hint : string;
|
47 |
|
|
lpm_representation : string;
|
48 |
|
|
lpm_type : string;
|
49 |
|
|
lpm_widtha : natural;
|
50 |
|
|
lpm_widthb : natural;
|
51 |
|
|
lpm_widthp : natural
|
52 |
|
|
);
|
53 |
|
|
port (
|
54 |
|
|
dataa : in std_logic_vector ( lpm_widtha-1 downto 0 );
|
55 |
|
|
datab : in std_logic_vector ( lpm_widthb-1 downto 0 );
|
56 |
|
|
result : out std_logic_vector( lpm_widthp-1 downto 0 )
|
57 |
|
|
);
|
58 |
115 |
jguarin200 |
end component;
|
59 |
108 |
jguarin200 |
|
60 |
118 |
jguarin200 |
signal s1zero : std_logic;
|
61 |
115 |
jguarin200 |
signal s1delta : std_logic_vector(5 downto 0);
|
62 |
|
|
signal s0delta,s1exp,s2exp,s3exp,s4exp,s5exp,s5factor,s6exp,s6factor: std_logic_vector(7 downto 0);
|
63 |
|
|
signal s1shifter,s5factorhot9 : std_logic_vector(8 downto 0);
|
64 |
|
|
signal s1pl,s5pl : std_logic_vector(17 downto 0);
|
65 |
|
|
signal s5postshift,s6postshift : std_logic_vector(22 downto 0);
|
66 |
|
|
signal s1umantshift,s1umantfixed,s1postshift,s1xorslab,s2xorslab : std_logic_vector(23 downto 0);
|
67 |
|
|
signal s2umantshift,s2mantfixed,s3mantfixed,s3mantshift,s4xorslab : std_logic_vector(24 downto 0);
|
68 |
|
|
signal s5factorhot25 : std_logic_vector(24 downto 0);
|
69 |
|
|
signal s4sresult,s5result,s6result : std_logic_vector(25 downto 0); -- Signed mantissa result
|
70 |
|
|
signal s1ph,s5ph : std_logic_vector(26 downto 0);
|
71 |
|
|
signal s0a,s0b : std_logic_vector(31 downto 0); -- Float 32 bit
|
72 |
114 |
jguarin200 |
|
73 |
115 |
jguarin200 |
begin
|
74 |
111 |
jguarin200 |
|
75 |
115 |
jguarin200 |
process (clk)
|
76 |
108 |
jguarin200 |
begin
|
77 |
115 |
jguarin200 |
if clk'event and clk='1' then
|
78 |
108 |
jguarin200 |
|
79 |
115 |
jguarin200 |
--!Registro de entrada
|
80 |
|
|
s0a <= a32;
|
81 |
|
|
s0b(31) <= dpc xor b32(31); --! Importante: Integrar el signo en el operando B
|
82 |
|
|
s0b(30 downto 0) <= b32(30 downto 0);
|
83 |
114 |
jguarin200 |
|
84 |
115 |
jguarin200 |
--!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ón si el mayor es a las posiciones la mantiene. Zero check.
|
85 |
|
|
--!signo,exponente,mantissa
|
86 |
118 |
jguarin200 |
if (s0b(30 downto 23)&s0a(30 downto 23))=x"0000" then
|
87 |
|
|
s1zero <= '0';
|
88 |
|
|
else
|
89 |
|
|
s1zero <= '1';
|
90 |
|
|
end if;
|
91 |
115 |
jguarin200 |
s1delta <= s0delta(7) & (s0delta(7) xor s0delta(4))&(s0delta(7) xor s0delta(4)) & s0delta(2 downto 0);
|
92 |
|
|
case s0delta(7) is
|
93 |
|
|
when '1' =>
|
94 |
|
|
s1exp <= s0b(30 downto 23);
|
95 |
|
|
s1umantshift <= s0a(31)&s0a(22 downto 0);
|
96 |
|
|
s1umantfixed <= s0b(31)&s0b(22 downto 0);
|
97 |
111 |
jguarin200 |
when others =>
|
98 |
115 |
jguarin200 |
s1exp <= s0a(30 downto 23);
|
99 |
|
|
s1umantshift <= s0b(31)&s0b(22 downto 0);
|
100 |
|
|
s1umantfixed <= s0a(31)&s0a(22 downto 0);
|
101 |
|
|
end case;
|
102 |
109 |
jguarin200 |
|
103 |
115 |
jguarin200 |
--! Etapa 1: Denormalización de la mantissas.
|
104 |
118 |
jguarin200 |
case s1delta(4 downto 3) is
|
105 |
115 |
jguarin200 |
when "00" => s2umantshift <= s1umantshift(23)&s1postshift(23 downto 0);
|
106 |
|
|
when "01" => s2umantshift <= s1umantshift(23)&x"00"&s1postshift(23 downto 8);
|
107 |
|
|
when "10" => s2umantshift <= s1umantshift(23)&x"0000"&s1postshift(23 downto 16);
|
108 |
|
|
when others => s2umantshift <= (others => '0');
|
109 |
|
|
end case;
|
110 |
117 |
jguarin200 |
s2mantfixed <= s1umantfixed(23) & ( ( ('1'&s1umantfixed(22 downto 0)) xor s1xorslab) + ( x"00000"&"000"&s1umantfixed(23) ) );
|
111 |
115 |
jguarin200 |
s2exp <= s1exp;
|
112 |
114 |
jguarin200 |
|
113 |
115 |
jguarin200 |
--! Etapa2: Signar la mantissa denormalizada.
|
114 |
|
|
s3mantfixed <= s2mantfixed;
|
115 |
117 |
jguarin200 |
s3mantshift <= s2umantshift(24)& ( ( s2umantshift(23 downto 0) xor s2xorslab) + ( x"00000"&"000"&s2umantshift(24) ) );
|
116 |
115 |
jguarin200 |
s3exp <= s2exp;
|
117 |
114 |
jguarin200 |
|
118 |
115 |
jguarin200 |
--! Etapa 3: Etapa 3 Realizar la suma, quitar el signo de la mantissa y codificar el corrimiento hacia la izquierda.
|
119 |
|
|
s4sresult <= (s3mantshift(24)&s3mantshift)+(s3mantfixed(24)&s3mantfixed);
|
120 |
|
|
s4exp <= s3exp;
|
121 |
114 |
jguarin200 |
|
122 |
115 |
jguarin200 |
--! Etapa 4: Quitar el signo a la mantissa resultante.
|
123 |
117 |
jguarin200 |
s5result <= s4sresult(25)&((s4sresult(24 downto 0) xor s4xorslab) +(x"000000"&s4sresult(25)));
|
124 |
115 |
jguarin200 |
s5exp <= s4exp;
|
125 |
114 |
jguarin200 |
|
126 |
|
|
|
127 |
115 |
jguarin200 |
--! Etapa 5: Codificar el corrimiento para la normalizacion de la mantissa resultante.
|
128 |
|
|
s6result <= s5result;
|
129 |
|
|
s6exp <= s5exp;
|
130 |
|
|
s6factor <= s5factor;
|
131 |
|
|
s6postshift <= s5postshift;
|
132 |
114 |
jguarin200 |
|
133 |
115 |
jguarin200 |
--! Etapa 6: Entregar el resultado.
|
134 |
|
|
c32(31) <= s6result(25);
|
135 |
118 |
jguarin200 |
c32(30 downto 23) <= s6exp+s6factor+x"ff";
|
136 |
115 |
jguarin200 |
case s6factor(4 downto 3) is
|
137 |
|
|
when "01" => c32(22 downto 0) <= s6postshift(14 downto 00)&x"00";
|
138 |
|
|
when "10" => c32(22 downto 0) <= s6postshift(06 downto 00)&x"0000";
|
139 |
|
|
when others => c32(22 downto 0) <= s6postshift;
|
140 |
|
|
end case;
|
141 |
109 |
jguarin200 |
end if;
|
142 |
108 |
jguarin200 |
end process;
|
143 |
115 |
jguarin200 |
--! Combinatorial gremlin, Etapa 0 el corrimiento de la mantissa con menor exponente y reorganiza los operandos,\n
|
144 |
|
|
--! si el mayor es b, intercambia las posición si el mayor es a las posiciones la mantiene.
|
145 |
|
|
s0delta <= s0a(30 downto 23)-s0b(30 downto 23);
|
146 |
|
|
--! Combinatorial Gremlin, Etapa 1 Codificar el factor de corrimiento de denormalizacion y denormalizar la mantissa no fija. Signar la mantissa que se queda fija.
|
147 |
|
|
decodeshiftfactor:
|
148 |
|
|
process (s1delta(2 downto 0))
|
149 |
114 |
jguarin200 |
begin
|
150 |
115 |
jguarin200 |
case s1delta(2 downto 0) is
|
151 |
|
|
when "111" => s1shifter(8 downto 0) <= '0'&s1delta(5)&"00000"¬(s1delta(5))&'0';
|
152 |
|
|
when "110" => s1shifter(8 downto 0) <= "00"&s1delta(5)&"000"¬(s1delta(5))&"00";
|
153 |
|
|
when "101" => s1shifter(8 downto 0) <= "000"&s1delta(5)&'0'¬(s1delta(5))&"000";
|
154 |
|
|
when "100" => s1shifter(8 downto 0) <= '0'&x"10";
|
155 |
|
|
when "011" => s1shifter(8 downto 0) <= "000"¬(s1delta(5))&'0'&s1delta(5)&"000";
|
156 |
|
|
when "010" => s1shifter(8 downto 0) <= "00"¬(s1delta(5))&"000"&s1delta(5)&"00";
|
157 |
|
|
when "001" => s1shifter(8 downto 0) <= '0'¬(s1delta(5))&"00000"&s1delta(5)&'0';
|
158 |
|
|
when others => s1shifter(8 downto 0) <= not(s1delta(5))&"0000000"&s1delta(5);
|
159 |
106 |
jguarin200 |
end case;
|
160 |
111 |
jguarin200 |
end process;
|
161 |
115 |
jguarin200 |
denormhighshiftermult:lpm_mult
|
162 |
111 |
jguarin200 |
generic map ("DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9","UNSIGNED","LPM_MULT",9,18,27)
|
163 |
118 |
jguarin200 |
port map (s1shifter,s1zero&s1umantshift(22 downto 06),s1ph);
|
164 |
115 |
jguarin200 |
denormlowshiftermult:lpm_mult
|
165 |
111 |
jguarin200 |
generic map ("DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9","UNSIGNED","LPM_MULT",9,9,18)
|
166 |
115 |
jguarin200 |
port map (s1shifter,s1umantshift(5 downto 0)&"000",s1pl);
|
167 |
107 |
jguarin200 |
|
168 |
115 |
jguarin200 |
s1postshift(23 downto 7) <= s1ph(25 downto 9);
|
169 |
|
|
s1postshift(06 downto 0) <= s1ph(08 downto 2) or s1pl(17 downto 11);
|
170 |
|
|
s1xorslab(23 downto 0) <= (others => s1umantfixed(23));
|
171 |
107 |
jguarin200 |
|
172 |
115 |
jguarin200 |
--! Combinatorial Gremlin, Etapa 2: Signar la mantissa denormalizada.
|
173 |
|
|
s2xorslab <= (others => s2umantshift(24));
|
174 |
|
|
|
175 |
|
|
--! Combinatorial Gremlin, Etapa 4: Quitar el signo de la mantissa resultante.
|
176 |
|
|
s4xorslab <= (others => s4sresult(25));
|
177 |
|
|
|
178 |
|
|
--! Combinatorial Gremlin, Etapa 5: Codificar el factor de normalizacion de la mantissa resultante.
|
179 |
|
|
normalizerdecodeshift:
|
180 |
|
|
process (s5result,s5factorhot25)
|
181 |
108 |
jguarin200 |
begin
|
182 |
115 |
jguarin200 |
s5factor<=(others => '0');
|
183 |
|
|
s5factorhot25 <= (others => '0');
|
184 |
114 |
jguarin200 |
for i in 24 downto 0 loop
|
185 |
115 |
jguarin200 |
if s5result(i)='1' then
|
186 |
116 |
jguarin200 |
s5factor <= conv_std_logic_vector(24-i,8);
|
187 |
115 |
jguarin200 |
s5factorhot25(24-i) <= '1';
|
188 |
111 |
jguarin200 |
exit;
|
189 |
|
|
end if;
|
190 |
108 |
jguarin200 |
end loop;
|
191 |
115 |
jguarin200 |
s5factorhot9 <= (s5factorhot25(8 downto 1)or s5factorhot25(16 downto 9)or s5factorhot25(24 downto 17)) & s5factorhot25(0);
|
192 |
|
|
end process;
|
193 |
|
|
normhighshiftermult:lpm_mult
|
194 |
|
|
generic map ("DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9","UNSIGNED","LPM_MULT",9,18,27)
|
195 |
|
|
port map (s5factorhot9,s5result(24 downto 7),s5ph);
|
196 |
|
|
normlowshiftermult:lpm_mult
|
197 |
|
|
generic map ("DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9","UNSIGNED","LPM_MULT",9,9,18)
|
198 |
|
|
port map (s5factorhot9,s5result(06 downto 0)&"00",s5pl);
|
199 |
|
|
s5postshift(22 downto 15) <= s5ph(16 downto 09);
|
200 |
117 |
jguarin200 |
s5postshift(14 downto 06) <= s5ph(08 downto 00); --! Activar este pedazo si se requiere extrema precision or s5pl(17 downto 9);
|
201 |
115 |
jguarin200 |
s5postshift(05 downto 00) <= s5pl(08 downto 03);
|
202 |
114 |
jguarin200 |
|
203 |
106 |
jguarin200 |
|
204 |
|
|
|
205 |
110 |
jguarin200 |
|
206 |
106 |
jguarin200 |
|
207 |
115 |
jguarin200 |
end ema32x2_arch;
|
208 |
106 |
jguarin200 |
|
209 |
108 |
jguarin200 |
|