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

Subversion Repositories raytrac

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

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

Line No. Rev Author Line
1 59 jguarin200
------------------------------------------------
2
--! @file shift.vhd
3
--! @brief RayTrac TestBench
4
--! @author Julián Andrés Guarín Reyes
5
--------------------------------------------------
6
 
7
 
8
-- RAYTRAC
9
-- Author Julian Andres Guarin
10
-- shift.vhd
11
-- This file is part of raytrac.
12
-- 
13
--     raytrac is free software: you can redistribute it and/or modify
14
--     it under the terms of the GNU General Public License as published by
15
--     the Free Software Foundation, either version 3 of the License, or
16
--     (at your option) any later version.
17
-- 
18
--     raytrac is distributed in the hope that it will be useful,
19
--     but WITHOUT ANY WARRANTY; without even the implied warranty of
20
--     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
--     GNU General Public License for more details.
22
-- 
23
--     You should have received a copy of the GNU General Public License
24
--     along with raytrac.  If not, see <http://www.gnu.org/licenses/>
25
library ieee;
26
use ieee.std_logic_1164.all;
27
use ieee.std_logic_arith.all;
28
use ieee.std_logic_signed.all;
29 60 jguarin200
use ieee.math_real.all;
30 59 jguarin200
 
31
 
32 67 jguarin200
--! \brief Dado que cualquier n&uacute;mero entero A, se puede escribir 2^n * f, es importante obtener una representaci&oacute;n del valor de f en base 2. Una vez hallado este valor y evaluado en una funci&oacute;n bastara con realizar un corrimiento a la izquierda n bits del resultado, para calcular funciones como A^-1 o A^0.5.
33 59 jguarin200
entity shifter is
34
        generic (
35 60 jguarin200
                address_width   : integer       := 9;
36
                width                   : integer       := 32;
37 78 jguarin200
                --! Cuando even shifter es "YES" se hara la busqueda del primer bit con valor 1, de izquierda a derecha, pero NO de uno en uno.
38 60 jguarin200
                even_shifter    : string        := "YES"
39
 
40 59 jguarin200
        );
41
        port (
42
                data                    : in std_logic_vector(width - 1 downto 0);
43 60 jguarin200
                exp                             : out std_logic_vector(integer(ceil(log(real(width),2.0)))-1 downto 0);
44 59 jguarin200
                address                 : out std_logic_vector (address_width-1 downto 0);
45 60 jguarin200
                zero                    : out std_logic
46 59 jguarin200
        );
47
end shifter;
48
 
49
architecture shifter_arch of shifter is
50 60 jguarin200
 
51 59 jguarin200
begin
52
 
53
        sanityLost:
54 60 jguarin200
        process (data)
55
                variable index: integer range-1 to width+address_width-1:=width+address_width-1;
56 59 jguarin200
 
57
        begin
58
                address<=(others=>'0');
59 60 jguarin200
                exp<=(others=>'0');
60
 
61
                zero<=data(0);
62
 
63
                if even_shifter="YES" then
64
                        index:=width-1;
65
                else
66
                        index:=width-2;
67
                end if;
68
 
69
                while index>=1 loop
70
                        if data(index)='1' then
71
                                zero<='0';
72
                                exp<=CONV_STD_LOGIC_VECTOR(index, exp'high+1);
73
                                if index>=address_width then
74
                                        address <= data (index-1 downto index-address_width);
75
                                else
76
                                        address(address_width-1 downto address_width-index) <= data (index-1 downto 0);
77
                                        address(address_width-index-1 downto 0) <= (others =>'0');
78 59 jguarin200
                                end if;
79
                                exit;
80
                        end if;
81 60 jguarin200
                        index:=index-2; --Boost
82
                end loop;
83 59 jguarin200
 
84 60 jguarin200
 
85
 
86
 
87 59 jguarin200
        end process sanityLost;
88
 
89 67 jguarin200
 
90 59 jguarin200
end shifter_arch;
91
 
92
 
93
 
94
 
95
 
96
 

powered by: WebSVN 2.1.0

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