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

Subversion Repositories raytrac

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

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
library ieee
24
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
                functype: string        := "SQUARE_ROOT";
37
                iwidth  : integer       := 32;
38
                owidth  : integer       := 16;
39
                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
        signal cumpaN                   : std_logic_vector (2*integer(ceil(log(real(iwidth),2.0)))-1 downto 0);
73
        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
        signal chiefN                   : std_logic_vector (2*integer(ceil(log(real(iwidth),2.0)))-1 downto 0);
78
        signal chiefF                   : std_logic_vector (c3width-1 downto 0);
79
 
80
 
81
begin
82
 
83
        !-- expomantis.
84
        expomantisreg:
85
        if reginput="YES" generate
86
                expomantisProc:
87
                process (clk,rst)
88
                begin
89
                        if rst=rstMasterValue then
90
                                expomantisvalue <= (others =>'0');
91
                        elsif clk'event and clk='1' then
92
                                expomantisvalue <= vale;
93
                        end if;
94
                end process expomantisProc;
95
        end generate expomantisreg;
96
        expomantisnoreg;
97
        if reginput ="NO" generate
98
                expomantisvalue<=value;
99
        end generate expomantisnoreg;
100
        expomantisshifter2x:shifter2xstage
101
        generic map(awidth,iwidth)
102
        port map(expomantisvalue,expomantisexp,expomantisadd,expomantiszero);
103
 
104
        --! funky.
105
        funkyProc:
106
        process (clk,rst)
107
        begin
108
                if rst=rstMasterValue then
109
                        funkyexp <= (others => '0');
110
 
111
                        funkyzero <= '0';
112
                else
113
                        funkyexp <= expomantisexp;
114
                        funkyzero <= expomantiszero;
115
                end if;
116
        end process funkyProc;
117
        funkyadd <= expomantisadd;
118
        funkyget:
119
        process (funkyexp)
120
        begin
121
                if (funkyexp(integer(ceil(log(real(iwidth),2.0)))-1 downto 0)>funkyexp(2*integer(ceil(log(real(iwidth),2.0)))-1 downto integer(ceil(log(real(iwidth),2.0))))) then
122
                        funkyselector<='0';
123
                else
124
                        funkyselector<='1';
125
                end if;
126
        end process funkyget;
127
        funkyinversion:
128
        if functype="INVERSION" generate
129
                meminvr:func
130
                generic map ("X:/Tesis/Workspace/hw/rt_lib/arith/src/trunk/sqrtdiv/meminvr.mif")
131
                port map(
132
                        funkyadd(integer(ceil(log(real(iwidth),2.0)))-1 downto 0),
133
                        funkyadd(2*integer(ceil(log(real(iwidth),2.0)))-1 downto integer(ceil(log(real(iwidth),2.0)))),
134
                        clk,
135
                        funkyq(c3width-1 downto 0),
136
                        funkyq(2*c3width-1 downto c3width));
137
        end generate funkyinversion;
138
        funkysquare_root:
139
        if functype="SQUARE_ROOT" generate
140
                sqrt: func
141
                generic map ("X:/Tesis/Workspace/hw/rt_lib/arith/src/trunk/sqrtdiv/memsqrt.mif")
142
                port map(
143
                        funkyadd(integer(ceil(log(real(iwidth),2.0)))-1 downto 0),
144
                        ad1 => (others => '0'),
145
                        clk,
146
                        funkyq(c3width-1 downto 0),
147
                        open);
148
 
149
                sqrt2x: func
150
                generic map ("X:/Tesis/Workspace/hw/rt_lib/arith/src/trunk/sqrtdiv/memsqrt2f.mif")
151
                port map(
152
                        ad0 => (others => '0'),
153
                        funkyadd(2*integer(ceil(log(real(iwidth),2.0)))-1 downto integer(ceil(log(real(iwidth),2.0)))),
154
                        clk,
155
                        open,
156
                        funkyq(2*c3width-1 downto c3width));
157
        end generate funkysquare_root;
158
 
159
 
160
        --! cumpa.
161
        cumpaProc:
162
        process (clk,rst)
163
        begin
164
                if rst=rstMasterValue then
165
                        cumpaselector <= (others => '0');
166
                        cumpazero <= (others => '0');
167
                        cumpaexp <= (others => '0');
168
                        cumpaq <= (others => '0');
169
                elsif clk'event and clk='1' then
170
                        cumpaselector <= funkyselector;
171
                        cumpazero <= funkyzero;
172
                        cumpaexp <= funkyexp;
173
                        cumpaq <= funkyq;
174
                end if;
175
        end process cumpaProc;
176
        cumpaMux:
177
        process (cumpaq,cumpaexp,cumpaselector)
178
        begin
179
                if cumpaselector='0' then
180
                        cumpaN<=cumpaexp(integer(ceil(log(real(iwidth),2.0)))-1 downto 0);
181
                        cumpaF<=cumpaq(c3width-1 downto 0);
182
                else
183
                        cumpaN<=cumpaexp(2*integer(ceil(log(real(iwidth),2.0)))-1 downto integer(ceil(log(real(iwidth),2.0))));
184
                        cumpaF<=cumpaq(2*c3width-1 downto c3width);
185
                end if;
186
        end process cumpaMux;
187
 
188
        --! chief.
189
        chiefProc:
190
        process (clk,rst)
191
        begin
192
                if rst=rstMasterValue then
193
                        chiefF <= (others => '0');
194
                        chiefN <= (others => '0');
195
                elsif clk'event and clk='1' then
196
                        chiefF <= cumpaF;
197
                        chiefN <= cumpaN;
198
                        zero <= cumpazero;
199
                end if;
200
        end process chiefProc;
201
        cumpaShifter: RLshifter
202
        generic map(functype,c3width,owidth)
203
        port map(chiefN,chiefF,result);
204
 
205
end sqrtdiv_arch;
206
 
207
 
208
 
209
 
210
 
211
 
212
 

powered by: WebSVN 2.1.0

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