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

Subversion Repositories hilbert_transformer

[/] [hilbert_transformer/] [trunk/] [vhdl/] [resize_tools.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 plutonium
-- functions for resizing vectors with the comma located at the MSB
2
-- resize_to_msb_trunc realizes a truncation to the new wordsize, if new_size is lower than old size
3
-- resize_to_msb_trunc realizes a rounding to the new wordsize, if new_size is lower than old size with the use of one additional adder
4
 
5
-- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License
6
-- as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
7
-- 
8
-- This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10
-- 
11
-- You should have received a copy of the GNU General Public License along with this program; 
12
-- if not, see <http://www.gnu.org/licenses/>.
13
 
14
-- Package Definition
15
library ieee;
16
use ieee.std_logic_1164.all;
17
use ieee.numeric_std.all;
18
 
19
package resize_tools_pkg is
20
 
21
  -- function declarations
22
 
23
  function resize_to_msb_trunc(
24
    x : std_logic_vector;
25
    new_size : integer
26
  ) return std_logic_vector;
27
 
28
  function resize_to_msb_round(
29
    x : std_logic_vector;
30
    new_size : integer
31
  ) return std_logic_vector;
32
 
33
end resize_tools_pkg;
34
 
35
-- package body
36
 
37
package body resize_tools_pkg is
38
 
39
  -- function implementations
40
 
41
  function resize_to_msb_trunc(
42
    x : std_logic_vector;
43
    new_size : integer
44
  ) return std_logic_vector is
45
        variable x_res : std_logic_vector(new_size-1 downto 0);
46
  begin
47
                if new_size > x'length then
48
                        x_res(new_size-1 downto new_size-x'length) := x;
49
                        x_res(new_size-x'length-1 downto 0) := (others => '0');
50
                elsif x'length >= new_size then
51
                        x_res := x(x'length-1 downto x'length-new_size);
52
                end if;
53
    return x_res;
54
  end resize_to_msb_trunc;
55
 
56
  function resize_to_msb_round(
57
    x : std_logic_vector;
58
    new_size : integer
59
  ) return std_logic_vector is
60
        variable x_res : std_logic_vector(new_size-1 downto 0);
61
  begin
62
                if x'length = new_size then
63
                        x_res := x;
64
                elsif new_size > x'length then
65
                        x_res(new_size-1 downto new_size-x'length) := x;
66
                        x_res(new_size-x'length-1 downto 0) := (others => '0');
67
                elsif x'length > new_size then
68
                        if x(x'length-new_size-1) = '1' then
69
                                x_res := std_logic_vector(signed(x(x'length-1 downto x'length-new_size)) + 1);
70
                        else
71
                                x_res := x(x'length-1 downto x'length-new_size);
72
                        end if;
73
                end if;
74
    return x_res;
75
  end resize_to_msb_round;
76
 
77
end resize_tools_pkg;
78
 

powered by: WebSVN 2.1.0

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