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

Subversion Repositories raytrac

[/] [raytrac/] [trunk/] [fpbranch/] [unrm/] [shftr.vhd] - Blame information for rev 108

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 106 jguarin200
library ieee;
2
use ieee.std_logic_1164.all;
3 108 jguarin200
use ieee.std_logic_unsigned.all;
4 106 jguarin200
 
5
 
6
 
7 108 jguarin200
entity fadd32 is
8 106 jguarin200
        port (
9 108 jguarin200
                a32,b32: in std_logic_vector(31 downto 0);
10
                dpc:in std_logic;
11
                c32:out std_logic_vector(31 downto 0);
12 106 jguarin200
        );
13 108 jguarin200
end fadd32;
14 106 jguarin200
 
15
 
16 108 jguarin200
architecture fadd32_arch of fadd32 is
17 106 jguarin200
 
18
        component lpm_mult
19
        generic (
20
                lpm_hint                        : string;
21
                lpm_representation      : string;
22
                lpm_type                        : string;
23
                lpm_widtha                      : natural;
24
                lpm_widthb                      : natural;
25
                lpm_widthp                      : natural
26
        );
27
        port (
28
                dataa   : in std_logic_vector ( lpm_widtha-1 downto 0 );
29
                datab   : in std_logic_vector ( lpm_widthb-1 downto 0 );
30
                result  : out std_logic_vector( lpm_widthp-1 downto 0 )
31
        );
32
        end component;
33 108 jguarin200
        signal sdelta,expunrm,expnrm: std_logic_vector(7 downto 0);
34 107 jguarin200
        signal pha,phb : std_logic_vector(26 downto 0);
35
        signal sfactora,sfactorb,sfactor : std_logic_vector(8 downto 0);
36 108 jguarin200
        signal sma,smb,ssma,ssmb,usm,uxm: std_logic_vector(24 downto 0);
37
        signal ssm: std_logic_vector(25 downto 0);
38
 
39 107 jguarin200
        signal slaba,slabb : std_logic_vector(14 downto 0);
40
        signal shiftslab : std_logic_vector(23 downto 0);
41
        signal xplaces,splaces : std_logic_vector (4 downto 0);
42 108 jguarin200
        signal sign : std_logic;
43
 
44 106 jguarin200
 
45
begin
46
 
47 108 jguarin200
        --! Manejo del cero
48
        i3e754zero:
49
        process (ea,eb)
50
        begin
51
 
52
                if ea="00" then
53
                        signa <= '0';
54
                else
55
                        signa <= signa;
56
                end if;
57
                if eb="00" then
58
                        signb <= '0';
59
                        expunrm <= ea;
60
                else
61
                        signb <= signb;
62
                        expunrm <= eb;
63
                end if;
64
                if ea=x"00" or eb=x"00" then
65
                        zero='1';
66
                        sdelta <= x"00";
67
                else
68
                        zero='0';
69
                        sdelta <= ea-eb;
70
                end if;
71
 
72
 
73
        end process;
74
 
75
        --! Manejo del Exponente, sumar el delta
76
        unrmexpo:
77
        process(expunrm,sdelta)
78
        begin
79
                expunrm <= expunrm+sdelta;
80
        end process;
81
 
82
 
83 107 jguarin200
        --! Decodificar la magnitud del corrimiento
84 108 jguarin200
        denormshiftmagnitude:
85
        process (sdelta(7),sdelta(4 downto 0),signa,signb)
86 106 jguarin200
        begin
87 107 jguarin200
                for i in 4 downto 0 loop
88 108 jguarin200
                        xplaces(i) <= sdelta(i) xor sdelta(7);
89 107 jguarin200
                end loop;
90 108 jguarin200
                splaces  <= xplaces+("0000"&sdelta(7));
91
                if sdelta(7)='1' then
92
                        shiftslab <= signa;--!b>a
93
 
94
                else
95
                        shiftslab <= signb;--!a>=b
96 107 jguarin200
                end if;
97
        end process;
98
        --! Decodificar el factor de corrimiento
99 108 jguarin200
        denormfactor:
100
        process (shiftslab,splaces)
101 107 jguarin200
        begin
102
                case splaces(2 downto 0) is
103
                        when x"0" => sfactor(8 downto 0) <= shiftslab(0 downto 0) & "10000000";
104
                        when x"1" => sfactor(8 downto 0) <= shiftslab(1 downto 0) & "1000000";
105
                        when x"2" => sfactor(8 downto 0) <= shiftslab(2 downto 0) & "100000";
106
                        when x"3" => sfactor(8 downto 0) <= shiftslab(3 downto 0) & "10000";
107
                        when x"4" => sfactor(8 downto 0) <= shiftslab(4 downto 0) & "1000";
108
                        when x"5" => sfactor(8 downto 0) <= shiftslab(5 downto 0) & "100";
109
                        when x"6" => sfactor(8 downto 0) <= shiftslab(6 downto 0) & "10";
110
                        when others => sfactor(8 downto 0) <=shiftslab(7 downto 0) &"1";
111 106 jguarin200
                end case;
112
        end process;
113 107 jguarin200
        --! Asignar el factor de corrimiento  las mantissas
114 108 jguarin200
        denomrselectmantissa2shift:
115
        process (sdelta(7),signa,signb)
116 106 jguarin200
        begin
117 108 jguarin200
                case sdelta(7) is
118 107 jguarin200
                        when '1' => -- Negativo b>a : se corre a delta espacios a la derecha y b se queda quieto
119
                                sfactorb <= signb&"10000000";
120
                                sfactora <= sfactor;
121
                        when others => -- Positivo a>=b : se corre a delta espacios a la derecha y a se queda quieto
122
                                sfactorb <= sfactor;
123
                                sfactora <= signa&"10000000";
124
                end case;
125
                slaba <= (others => signa);
126
                slabb <= (others => signb);
127 108 jguarin200
        end process;
128 107 jguarin200
 
129
 
130
 
131
        --! Correr las mantissas y calcularlas.
132
        hmulta: lpm_mult
133
        generic map ("DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9","SIGNED","LPM_MULT",9,18,27)
134
        port    map (sfactora,signa&'1'&data24a(22 downto 0),pha);
135
        lmulta: lpm_mult
136
        generic map ("DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9","SIGNED","LPM_MULT",9,9,27)
137
        port    map (sfactora,signa&'1'&data24a(6 downto 0),pla);
138
        hmultb: lpm_mult
139
        generic map ("DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9","SIGNED","LPM_MULT",9,18,27)
140
        port    map (sfactorb,signb&'1'&data24b(22 downto 0),phb);
141
        lmultb: lpm_mult
142
        generic map ("DEDICATED_MULTIPLIER_CIRCUITRY=YES,MAXIMIZE_SPEED=9","SIGNED","LPM_MULT",9,9,27)
143
        port    map (sfactorb,signb&'1'&data24b(6 downto 0),plb);
144 108 jguarin200
        mantissadenorm:
145
        process(pha,phb,slaba,slabb)
146
        begin
147
                sma <= pha(24 downto 0) + (slaba&pla(17 downto 8));
148
                smb <= phb(24 downto 0) + (slabb&plb(17 downto 8));
149
        end process;
150 107 jguarin200
 
151
        --! Sumar las mantissas signadas y colocar los 0's que hagan falta 
152 108 jguarin200
        mantissaadding:
153
        process (sdelta(7),sma,smb,splaces(4 downto 3),zero)
154 107 jguarin200
        begin
155
 
156 108 jguarin200
                case sdelta(7) is
157 107 jguarin200
                        when '1' => -- Negativo b>a : se corre a delta espacios a la derecha y b se queda quieto 
158
                                ssmb <= smb;
159
                                case splaces(4 downto 3) is
160
                                        when x"3" => ssma <= (sma(24)&shiftslab(23 downto 0));
161
                                        when x"2" => ssma <= (sma(24)&shiftslab(15 downto 0)&sma(23 downto 16));
162
                                        when x"1" => ssma <= (sma(24)&shiftslab(7 downto 0)&sma(23 downto 8));
163
                                        when others => ssma <= sma;
164
                                end case;
165
                        when others => -- Positivo a>=b : se corre a delta espacios a la derecha y a se queda quieto
166 108 jguarin200
                                ssma <= sma;
167 107 jguarin200
                                case splaces(4 downto 3) is
168
                                        when x"3" => ssmb <= (smb(24)&shiftslab(23 downto 0));
169
                                        when x"2" => ssmb <= (smb(24)&shiftslab(15 downto 0)&smb(23 downto 16));
170
                                        when x"1" => ssmb <= (smb(24)&shiftslab(7 downto 0)&smb(23 downto 8));
171
                                        when others => ssmb <= smb;
172
                                end case;
173
                end case;
174 108 jguarin200
                if zero='0' then
175
                        ssm <= (ssma(24)&ssma)+(ssmb(24)&ssmb);
176
                else
177
                        ssm <= (ssma(24)&ssma)or(ssmb(24)&ssmb);
178
                end if;
179
        end process;
180 107 jguarin200
 
181 108 jguarin200
        --! Mantissas sumadas, designar
182
        unsignmantissa:
183
        process(ssm)
184
        begin
185
                for i in 24 downto 0 loop
186
                        usm(i) <= ssm(25) xor ssm(i);
187
                end loop;
188
                sign <= ssm(25);
189
                uxm <= usm+(x"000000"&sign);
190 106 jguarin200
        end process;
191
 
192 108 jguarin200
        --!Normalizar Mantissa y exponente
193
        process (uxm,expunrm)
194
                variable xshift : integer range 24 downto 0;
195
        begin
196
                for i in 24 downto 0 loop
197
                        if uxm(i)='1' then
198
                                xshift:=24-i;
199
                        end of;
200
                end loop;
201
                nplaces <= conv_std_logic_vector(xshift,5);
202
                expnrm <= expunrm-(("000"&nplaces)+x"ff");
203
        end process;
204 106 jguarin200
 
205 108 jguarin200
 
206 107 jguarin200
 
207 106 jguarin200
 
208
 
209 108 jguarin200
end fadd32_arch;
210 106 jguarin200
 
211
 
212
 
213
 
214
 
215
 
216
 
217 108 jguarin200
 

powered by: WebSVN 2.1.0

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