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

Subversion Repositories viterbi_decoder_axi4s

[/] [viterbi_decoder_axi4s/] [trunk/] [packages/] [pkg_helper.vhd] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mfehrenz
--!
2 6 mfehrenz
--! Copyright (C) 2011 - 2014 Creonic GmbH
3 2 mfehrenz
--!
4
--! This file is part of the Creonic Viterbi Decoder, which is distributed
5
--! under the terms of the GNU General Public License version 2.
6
--!
7
--! @file
8
--! @brief  Helper package with useful functions
9
--! @author Markus Fehrenz
10
--! @date   2011/12/02
11
--!
12
 
13
library ieee;
14
use ieee.std_logic_1164.all;
15
use ieee.numeric_std.all;
16
 
17
 
18
package pkg_helper is
19
 
20
        --!
21
        --! Return the log_2 of an natural value, i.e. the number of bits required
22
        --! to represent this unsigned value.
23
        --!
24
        function no_bits_natural(value_in : natural) return natural;
25
 
26
        --! Return maximum of two input values
27
        function max(value_in_a, value_in_b : natural) return natural;
28
 
29
end pkg_helper;
30
 
31
 
32
package body pkg_helper is
33
 
34
        function no_bits_natural(value_in: natural) return natural is
35
                variable v_n_bit : unsigned(31 downto 0);
36
        begin
37
                if value_in = 0 then
38
                        return 0;
39
                end if;
40
                v_n_bit := to_unsigned(value_in, 32);
41
                for i in 31 downto 0 loop
42
                        if v_n_bit(i) = '1' then
43
                                return i + 1;
44
                        end if;
45
                end loop;
46
                return 1;
47
        end no_bits_natural;
48
 
49
        function max(value_in_a, value_in_b : natural) return natural is
50
        begin
51
                if value_in_a > value_in_b then
52
                        return value_in_a;
53
                else
54
                        return value_in_b;
55
                end if;
56
        end function;
57
 
58
end pkg_helper;

powered by: WebSVN 2.1.0

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