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

Subversion Repositories raytrac

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

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
                even_shifter    : string        := "YES"
38
 
39 59 jguarin200
        );
40
        port (
41
                data                    : in std_logic_vector(width - 1 downto 0);
42 60 jguarin200
                exp                             : out std_logic_vector(integer(ceil(log(real(width),2.0)))-1 downto 0);
43 59 jguarin200
                address                 : out std_logic_vector (address_width-1 downto 0);
44 60 jguarin200
                zero                    : out std_logic
45 59 jguarin200
        );
46
end shifter;
47
 
48
architecture shifter_arch of shifter is
49 60 jguarin200
 
50 59 jguarin200
begin
51
 
52
        sanityLost:
53 60 jguarin200
        process (data)
54
                variable index: integer range-1 to width+address_width-1:=width+address_width-1;
55 59 jguarin200
 
56
        begin
57
                address<=(others=>'0');
58 60 jguarin200
                exp<=(others=>'0');
59
 
60
                zero<=data(0);
61
 
62
                if even_shifter="YES" then
63
                        index:=width-1;
64
                else
65
                        index:=width-2;
66
                end if;
67
 
68
                while index>=1 loop
69
                        if data(index)='1' then
70
                                zero<='0';
71
                                exp<=CONV_STD_LOGIC_VECTOR(index, exp'high+1);
72
                                if index>=address_width then
73
                                        address <= data (index-1 downto index-address_width);
74
                                else
75
                                        address(address_width-1 downto address_width-index) <= data (index-1 downto 0);
76
                                        address(address_width-index-1 downto 0) <= (others =>'0');
77 59 jguarin200
                                end if;
78
                                exit;
79
                        end if;
80 60 jguarin200
                        index:=index-2; --Boost
81
                end loop;
82 59 jguarin200
 
83 60 jguarin200
 
84
 
85
 
86 59 jguarin200
        end process sanityLost;
87
 
88 67 jguarin200
 
89 59 jguarin200
end shifter_arch;
90
 
91
 
92
 
93
 
94
 
95
 

powered by: WebSVN 2.1.0

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