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

Subversion Repositories raytrac

[/] [raytrac/] [trunk/] [sqrtdiv/] [sqrtdiv.vhd] - Blame information for rev 75

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

Line No. Rev Author Line
1 73 jguarin200
--! @file sqrtdiv.vhd
2
--! @brief Unidad aritm'etica para calcular la potencia de un n'umero entero elevado a la -1 (INVERSION) o a la 0.5 (SQUARE_ROOT).
3
--! @author Juli´n Andrés Guarín Reyes.
4
-- RAYTRAC
5
-- Author Julian Andres Guarin
6
-- sqrtdiv.vhd
7
-- This file is part of raytrac.
8
-- 
9
--     raytrac is free software: you can redistribute it and/or modify
10
--     it under the terms of the GNU General Public License as published by
11
--     the Free Software Foundation, either version 3 of the License, or
12
--     (at your option) any later version.
13
-- 
14
--     raytrac is distributed in the hope that it will be useful,
15
--     but WITHOUT ANY WARRANTY; without even the implied warranty of
16
--     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
--     GNU General Public License for more details.
18
-- 
19
--     You should have received a copy of the GNU General Public License
20
--     along with raytrac.  If not, see <http://www.gnu.org/licenses/>.
21
 
22
 
23 74 jguarin200
library ieee;
24 73 jguarin200
use ieee.std_logic_1164.all;
25
use ieee.std_logic_arith.all;
26
use ieee.std_logic_unsigned.all;
27
use ieee.math_real.all;
28
 
29
use work.arithpack.all;
30
 
31
 
32
entity sqrtdiv is
33
        generic (
34
                reginput: string        := "YES";
35
                c3width : integer       := 18;
36 74 jguarin200
                functype: string        := "INVERSION";
37 73 jguarin200
                iwidth  : integer       := 32;
38 74 jguarin200
                owidth  : integer       := 18;
39 73 jguarin200
                awidth  : integer       := 9
40
        );
41
        port (
42
                clk,rst : in std_logic;
43
                value   : in std_logic_vector (iwidth-1 downto 0);
44
                zero    : out std_logic;
45
                result  : out std_logic_vector (owidth-1 downto 0)
46
        );
47
end sqrtdiv;
48
 
49
architecture sqrtdiv_arch of sqrtdiv is
50
 
51
        --! expomantis::Primera etapa: Calculo parcial de la mantissa y el exponente.
52
        signal expomantisvalue  : std_logic_vector (iwidth-1 downto 0);
53
 
54
        signal expomantisexp    : std_logic_vector (2*integer(ceil(log(real(iwidth),2.0)))-1 downto 0);
55
        signal expomantisadd    : std_logic_vector (2*awidth-1 downto 0);
56
        signal expomantiszero   : std_logic;
57
 
58
        --! funky::Segunda etapa: Calculo del valor de la funcion evaluada en f.
59
        signal funkyadd                 : std_logic_vector (2*awidth-1 downto 0);
60
        signal funkyexp                 : std_logic_vector (2*integer(ceil(log(real(iwidth),2.0)))-1 downto 0);
61
        signal funkyzero                : std_logic;
62
 
63 75 jguarin200
        signal funkyq                   : std_logic_vector (2*c3width+3 downto 0);
64 73 jguarin200
        signal funkyselector    : std_logic;
65
 
66
        --! cumpa::Tercera etapa: Selecci'on de valores de acuerdo al exp escogido.
67
        signal cumpaexp                 : std_logic_vector (2*integer(ceil(log(real(iwidth),2.0)))-1 downto 0);
68 75 jguarin200
        signal cumpaq                   : std_logic_vector (2*c3width+3 downto 0);
69 73 jguarin200
        signal cumpaselector    : std_logic;
70
        signal cumpazero                : std_logic;
71
 
72 74 jguarin200
        signal cumpaN                   : std_logic_vector (integer(ceil(log(real(iwidth),2.0)))-1 downto 0);
73 75 jguarin200
        signal cumpaF                   : std_logic_vector (c3width+1 downto 0);
74 73 jguarin200
 
75
        --! chief::Cuarta etapa: Corrimiento a la izquierda o derecha, para el caso de la ra'iz cuadrada o la inversi'on respectivamente. 
76
 
77 74 jguarin200
        signal chiefN                   : std_logic_vector (integer(ceil(log(real(iwidth),2.0)))-1 downto 0);
78 75 jguarin200
        signal chiefF                   : std_logic_vector (c3width+1 downto 0);
79 73 jguarin200
 
80
 
81 74 jguarin200
        --! Constantes para manejar el tama&ntilde;o de los vectores
82
        constant exp1H : integer := 2*integer(ceil(log(real(iwidth),2.0)))-1;
83
        constant exp1L : integer := integer(ceil(log(real(iwidth),2.0)));
84
        constant exp0H : integer := exp1L-1;
85
        constant exp0L : integer := 0;
86
        constant add1H : integer := 2*awidth-1;
87
        constant add1L : integer := awidth;
88 75 jguarin200
        constant add0H : integer := awidth-1;
89 74 jguarin200
        constant add0L : integer := 0;
90
 
91
 
92 75 jguarin200
        constant c3qHH : integer := 2*c3width+3;
93
        constant c3qHL : integer := c3width+2;
94
        constant c3qLH : integer := c3width+1;
95 74 jguarin200
        constant c3qLL : integer := 0;
96
 
97 73 jguarin200
begin
98
 
99 74 jguarin200
        --! expomantis.
100 73 jguarin200
        expomantisreg:
101
        if reginput="YES" generate
102
                expomantisProc:
103
                process (clk,rst)
104
                begin
105
                        if rst=rstMasterValue then
106
                                expomantisvalue <= (others =>'0');
107
                        elsif clk'event and clk='1' then
108 74 jguarin200
                                expomantisvalue <= value;
109 73 jguarin200
                        end if;
110
                end process expomantisProc;
111
        end generate expomantisreg;
112 74 jguarin200
 
113
        expomantisnoreg:
114 73 jguarin200
        if reginput ="NO" generate
115
                expomantisvalue<=value;
116
        end generate expomantisnoreg;
117 74 jguarin200
 
118 73 jguarin200
        expomantisshifter2x:shifter2xstage
119
        generic map(awidth,iwidth)
120
        port map(expomantisvalue,expomantisexp,expomantisadd,expomantiszero);
121
 
122
        --! funky.
123
        funkyProc:
124 74 jguarin200
        process (clk,rst,expomantisexp, expomantiszero)
125 73 jguarin200
        begin
126
                if rst=rstMasterValue then
127
                        funkyexp <= (others => '0');
128
                        funkyzero <= '0';
129 75 jguarin200
                        funkyadd <= (others => '0');
130
 
131 74 jguarin200
                elsif clk'event and clk='1' then
132 75 jguarin200
 
133 74 jguarin200
                        funkyexp(exp1H downto 0) <= expomantisexp(exp1H downto 0);
134 73 jguarin200
                        funkyzero <= expomantiszero;
135 75 jguarin200
                        funkyadd <= expomantisadd;
136
 
137 73 jguarin200
                end if;
138
        end process funkyProc;
139 75 jguarin200
 
140 73 jguarin200
        funkyget:
141
        process (funkyexp)
142
        begin
143 74 jguarin200
                if (funkyexp(exp0H downto 0)>funkyexp(exp1H downto exp1L)) then
144 73 jguarin200
                        funkyselector<='0';
145
                else
146
                        funkyselector<='1';
147
                end if;
148
        end process funkyget;
149 74 jguarin200
 
150 73 jguarin200
        funkyinversion:
151
        if functype="INVERSION" generate
152
                meminvr:func
153 75 jguarin200
                generic map ("../../../MinGW/MSys/1.0/home/julian/code/testbench/trunk/utils/arachnophobia.mif")
154
                --generic map ("X:/Tesis/Workspace/hw/rt_lib/arith/src/trunk/sqrtdiv/meminvr.mif")
155 73 jguarin200
                port map(
156 75 jguarin200
                        expomantisadd(awidth-1 downto 0),
157
                        expomantisadd(2*awidth-1 downto awidth),
158 73 jguarin200
                        clk,
159 75 jguarin200
                        funkyq(c3qLH-2 downto c3qLL),
160
                        funkyq(c3qHH-2 downto c3qHL));
161
                funkynibbles:
162
                process(funkyadd)
163
                begin
164
 
165
                        if funkyadd(awidth-1 downto 0) = conv_std_logic_vector(0,awidth) then
166
                                funkyq(c3qLH downto c3qLH-1) <= "10";
167
                        else
168
                                funkyq(c3qLH downto c3qLH-1) <= "01";
169
                        end if;
170
                        if funkyadd(2*awidth-1 downto awidth) = conv_std_logic_vector(0,awidth) then
171
                                funkyq(c3qHH downto c3qHH-1) <= "10";
172
                        else
173
                                funkyq(c3qHH downto c3qHH-1) <= "01";
174
                        end if;
175
                end process funkynibbles;
176
 
177 73 jguarin200
        end generate funkyinversion;
178
        funkysquare_root:
179
        if functype="SQUARE_ROOT" generate
180
                sqrt: func
181 75 jguarin200
                generic map ("../../../MinGW/MSys/1.0/home/julian/code/testbench/trunk/utils/phobia.mif")
182
                --generic map ("X:/Tesis/Workspace/hw/rt_lib/arith/src/trunk/sqrtdiv/memsqrt.mif")
183 73 jguarin200
                port map(
184 75 jguarin200
                        expomantisadd(awidth-1 downto 0),
185 74 jguarin200
                        (others => '0'),
186 73 jguarin200
                        clk,
187 75 jguarin200
                        funkyq(c3qLH-2 downto c3qLL),
188 73 jguarin200
                        open);
189
 
190
                sqrt2x: func
191 75 jguarin200
                generic map ("../../../MinGW/MSys/1.0/home/julian/code/testbench/trunk/utils/phobia2.mif")
192
                --generic map ("X:/Tesis/Workspace/hw/rt_lib/arith/src/trunk/sqrtdiv/memsqrt2f.mif")
193 73 jguarin200
                port map(
194 74 jguarin200
                        (others => '0'),
195 75 jguarin200
                        expomantisadd(2*awidth-1 downto awidth),
196 73 jguarin200
                        clk,
197
                        open,
198 75 jguarin200
                        funkyq(c3qHH-2 downto c3qHL));
199
                funkynibbles:
200
                process(funkyadd)
201
                begin
202
                        --! Siempre ser'a 2 el nibble mas significativo cuando estemos calculando f**0.5. 
203
                        funkyq(c3qLH downto c3qLH-1) <= "10";
204
                        --! Siempre ser'a 1 el bit mas significativo cuando estemos calculando 2f**0.5.
205
                        funkyq(c3qHH) <= '1';
206
                        if funkyadd(2*awidth-1 downto awidth) >= conv_std_logic_vector(64,awidth) then
207
                                funkyq(c3qHH-1) <= '1';
208
                        else
209
                                funkyq(c3qHH-1) <= '0';
210
                        end if;
211
                end process funkynibbles;
212
 
213 73 jguarin200
        end generate funkysquare_root;
214
 
215
        --! cumpa.
216
        cumpaProc:
217
        process (clk,rst)
218
        begin
219
                if rst=rstMasterValue then
220 74 jguarin200
                        cumpaselector <= '0';
221
                        cumpazero <= '0';
222 73 jguarin200
                        cumpaexp <= (others => '0');
223
                        cumpaq <= (others => '0');
224
                elsif clk'event and clk='1' then
225
                        cumpaselector <= funkyselector;
226
                        cumpazero <= funkyzero;
227
                        cumpaexp <= funkyexp;
228
                        cumpaq <= funkyq;
229
                end if;
230
        end process cumpaProc;
231
        cumpaMux:
232
        process (cumpaq,cumpaexp,cumpaselector)
233
        begin
234
                if cumpaselector='0' then
235 74 jguarin200
                        cumpaN<=cumpaexp(exp0H downto exp0L);
236
                        cumpaF<=cumpaq(c3qLH downto c3qLL);
237 73 jguarin200
                else
238 74 jguarin200
                        cumpaN<=cumpaexp(exp1H downto exp1L);
239
                        cumpaF<=cumpaq(c3qHH downto c3qHL);
240 73 jguarin200
                end if;
241
        end process cumpaMux;
242
 
243
        --! chief.
244
        chiefProc:
245
        process (clk,rst)
246
        begin
247
                if rst=rstMasterValue then
248
                        chiefF <= (others => '0');
249
                        chiefN <= (others => '0');
250
                elsif clk'event and clk='1' then
251
                        chiefF <= cumpaF;
252
                        chiefN <= cumpaN;
253
                        zero <= cumpazero;
254
                end if;
255
        end process chiefProc;
256 74 jguarin200
        chiefShifter: RLshifter
257 75 jguarin200
        generic map(functype,c3width+2,iwidth,owidth)
258 74 jguarin200
        port map(
259
                chiefN,
260
                chiefF,
261
                result);
262 73 jguarin200
 
263
end sqrtdiv_arch;
264
 
265
 
266
 
267
 
268
 
269
 
270
 

powered by: WebSVN 2.1.0

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