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

Subversion Repositories raytrac

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

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 78 jguarin200
                iwidth  : integer       := 18;
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 76 jguarin200
                generic map (memoryPath&"meminvr.mif")
154 73 jguarin200
                port map(
155 75 jguarin200
                        expomantisadd(awidth-1 downto 0),
156
                        expomantisadd(2*awidth-1 downto awidth),
157 73 jguarin200
                        clk,
158 75 jguarin200
                        funkyq(c3qLH-2 downto c3qLL),
159
                        funkyq(c3qHH-2 downto c3qHL));
160
 
161 73 jguarin200
        end generate funkyinversion;
162
        funkysquare_root:
163
        if functype="SQUARE_ROOT" generate
164
                sqrt: func
165 76 jguarin200
                generic map (memoryPath&"memsqrt.mif")
166 73 jguarin200
                port map(
167 75 jguarin200
                        expomantisadd(awidth-1 downto 0),
168 74 jguarin200
                        (others => '0'),
169 73 jguarin200
                        clk,
170 75 jguarin200
                        funkyq(c3qLH-2 downto c3qLL),
171 73 jguarin200
                        open);
172
 
173
                sqrt2x: func
174 76 jguarin200
                generic map ("memsqrt2f.mif")
175 73 jguarin200
                port map(
176 74 jguarin200
                        (others => '0'),
177 75 jguarin200
                        expomantisadd(2*awidth-1 downto awidth),
178 73 jguarin200
                        clk,
179
                        open,
180 75 jguarin200
                        funkyq(c3qHH-2 downto c3qHL));
181 79 jguarin200
 
182 73 jguarin200
        end generate funkysquare_root;
183
 
184
        --! cumpa.
185
        cumpaProc:
186
        process (clk,rst)
187
        begin
188
                if rst=rstMasterValue then
189 74 jguarin200
                        cumpaselector <= '0';
190
                        cumpazero <= '0';
191 73 jguarin200
                        cumpaexp <= (others => '0');
192
                        cumpaq <= (others => '0');
193
                elsif clk'event and clk='1' then
194
                        cumpaselector <= funkyselector;
195
                        cumpazero <= funkyzero;
196
                        cumpaexp <= funkyexp;
197
                        cumpaq <= funkyq;
198
                end if;
199
        end process cumpaProc;
200
        cumpaMux:
201
        process (cumpaq,cumpaexp,cumpaselector)
202
        begin
203
                if cumpaselector='0' then
204 74 jguarin200
                        cumpaN<=cumpaexp(exp0H downto exp0L);
205
                        cumpaF<=cumpaq(c3qLH downto c3qLL);
206 73 jguarin200
                else
207 74 jguarin200
                        cumpaN<=cumpaexp(exp1H downto exp1L);
208
                        cumpaF<=cumpaq(c3qHH downto c3qHL);
209 73 jguarin200
                end if;
210
        end process cumpaMux;
211
 
212
        --! chief.
213
        chiefProc:
214
        process (clk,rst)
215
        begin
216
                if rst=rstMasterValue then
217
                        chiefF <= (others => '0');
218
                        chiefN <= (others => '0');
219
                elsif clk'event and clk='1' then
220
                        chiefF <= cumpaF;
221
                        chiefN <= cumpaN;
222
                        zero <= cumpazero;
223
                end if;
224
        end process chiefProc;
225 74 jguarin200
        chiefShifter: RLshifter
226 75 jguarin200
        generic map(functype,c3width+2,iwidth,owidth)
227 74 jguarin200
        port map(
228
                chiefN,
229
                chiefF,
230
                result);
231 73 jguarin200
 
232
end sqrtdiv_arch;
233
 
234
 
235
 
236
 
237
 
238
 
239
 

powered by: WebSVN 2.1.0

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