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

Subversion Repositories raytrac

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

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
        signal funkyq                   : std_logic_vector (2*c3width-1 downto 0);
64
        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
        signal cumpaq                   : std_logic_vector (2*c3width-1 downto 0);
69
        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 73 jguarin200
        signal cumpaF                   : std_logic_vector (c3width-1 downto 0);
74
 
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 73 jguarin200
        signal chiefF                   : std_logic_vector (c3width-1 downto 0);
79
 
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
        constant add0H : integer := add1L-1;
89
        constant add0L : integer := 0;
90
 
91
 
92
        constant c3qHH : integer := 2*c3width-1;
93
        constant c3qHL : integer := c3width;
94
        constant c3qLH : integer := c3width-1;
95
        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 74 jguarin200
                elsif clk'event and clk='1' then
130
                        funkyexp(exp1H downto 0) <= expomantisexp(exp1H downto 0);
131 73 jguarin200
                        funkyzero <= expomantiszero;
132
                end if;
133
        end process funkyProc;
134
        funkyadd <= expomantisadd;
135
        funkyget:
136
        process (funkyexp)
137
        begin
138 74 jguarin200
                if (funkyexp(exp0H downto 0)>funkyexp(exp1H downto exp1L)) then
139 73 jguarin200
                        funkyselector<='0';
140
                else
141
                        funkyselector<='1';
142
                end if;
143
        end process funkyget;
144 74 jguarin200
 
145 73 jguarin200
        funkyinversion:
146
        if functype="INVERSION" generate
147
                meminvr:func
148
                generic map ("X:/Tesis/Workspace/hw/rt_lib/arith/src/trunk/sqrtdiv/meminvr.mif")
149
                port map(
150 74 jguarin200
                        funkyadd(add0H downto add0L),
151
                        funkyadd(add1H downto add1L),
152 73 jguarin200
                        clk,
153 74 jguarin200
                        funkyq(c3qLH downto c3qLL),
154
                        funkyq(c3qHH downto c3qHL));
155 73 jguarin200
        end generate funkyinversion;
156
        funkysquare_root:
157
        if functype="SQUARE_ROOT" generate
158
                sqrt: func
159
                generic map ("X:/Tesis/Workspace/hw/rt_lib/arith/src/trunk/sqrtdiv/memsqrt.mif")
160
                port map(
161 74 jguarin200
                        funkyadd(add0H downto add0L),
162
                        (others => '0'),
163 73 jguarin200
                        clk,
164 74 jguarin200
                        funkyq(c3qLH downto c3qLL),
165 73 jguarin200
                        open);
166
 
167
                sqrt2x: func
168
                generic map ("X:/Tesis/Workspace/hw/rt_lib/arith/src/trunk/sqrtdiv/memsqrt2f.mif")
169
                port map(
170 74 jguarin200
                        (others => '0'),
171
                        funkyadd(add1H downto add1L),
172 73 jguarin200
                        clk,
173
                        open,
174 74 jguarin200
                        funkyq(c3qHH downto c3qHL));
175 73 jguarin200
        end generate funkysquare_root;
176
 
177
        --! cumpa.
178
        cumpaProc:
179
        process (clk,rst)
180
        begin
181
                if rst=rstMasterValue then
182 74 jguarin200
                        cumpaselector <= '0';
183
                        cumpazero <= '0';
184 73 jguarin200
                        cumpaexp <= (others => '0');
185
                        cumpaq <= (others => '0');
186
                elsif clk'event and clk='1' then
187
                        cumpaselector <= funkyselector;
188
                        cumpazero <= funkyzero;
189
                        cumpaexp <= funkyexp;
190
                        cumpaq <= funkyq;
191
                end if;
192
        end process cumpaProc;
193
        cumpaMux:
194
        process (cumpaq,cumpaexp,cumpaselector)
195
        begin
196
                if cumpaselector='0' then
197 74 jguarin200
                        cumpaN<=cumpaexp(exp0H downto exp0L);
198
                        cumpaF<=cumpaq(c3qLH downto c3qLL);
199 73 jguarin200
                else
200 74 jguarin200
                        cumpaN<=cumpaexp(exp1H downto exp1L);
201
                        cumpaF<=cumpaq(c3qHH downto c3qHL);
202 73 jguarin200
                end if;
203
        end process cumpaMux;
204
 
205
        --! chief.
206
        chiefProc:
207
        process (clk,rst)
208
        begin
209
                if rst=rstMasterValue then
210
                        chiefF <= (others => '0');
211
                        chiefN <= (others => '0');
212
                elsif clk'event and clk='1' then
213
                        chiefF <= cumpaF;
214
                        chiefN <= cumpaN;
215
                        zero <= cumpazero;
216
                end if;
217
        end process chiefProc;
218 74 jguarin200
        chiefShifter: RLshifter
219
        generic map(functype,c3width,iwidth,owidth)
220
        port map(
221
                chiefN,
222
                chiefF,
223
                result);
224 73 jguarin200
 
225
end sqrtdiv_arch;
226
 
227
 
228
 
229
 
230
 
231
 
232
 

powered by: WebSVN 2.1.0

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