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

Subversion Repositories potato

[/] [potato/] [trunk/] [src/] [pp_utilities.vhd] - Blame information for rev 34

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

Line No. Rev Author Line
1 2 skordal
-- The Potato Processor - A simple processor for FPGAs
2
-- (c) Kristian Klomsten Skordal 2014 <kristian.skordal@wafflemail.net>
3 3 skordal
-- Report bugs and issues on <http://opencores.org/project,potato,bugtracker>
4 2 skordal
 
5
library ieee;
6
use ieee.std_logic_1164.all;
7
 
8
use work.pp_types.all;
9
use work.pp_constants.all;
10
 
11
package pp_utilities is
12
 
13
        --! Converts a boolean to an std_logic.
14
        function to_std_logic(input : in boolean) return std_logic;
15
 
16
        -- Checks if a number is 2^n:
17
        function is_pow2(input : in natural) return boolean;
18
 
19
        --! Calculates log2 with integers.
20
        function log2(input : in natural) return natural;
21
 
22
end package pp_utilities;
23
 
24
package body pp_utilities is
25
 
26
        function to_std_logic(input : in boolean) return std_logic is
27
        begin
28
                if input then
29
                        return '1';
30
                else
31
                        return '0';
32
                end if;
33
        end function to_std_logic;
34
 
35
        function is_pow2(input : in natural) return boolean is
36
                variable c : natural := 1;
37
        begin
38
                for i in 0 to 31 loop
39
                        if input = i then
40
                                return true;
41
                        end if;
42
 
43
                        c := c * 2;
44
                end loop;
45
 
46
                return false;
47
        end function is_pow2;
48
 
49
        function log2(input : in natural) return natural is
50
                variable retval : natural := 0;
51
                variable temp   : natural := input;
52
        begin
53
                while temp > 1 loop
54
                        retval := retval + 1;
55
                        temp := temp / 2;
56
                end loop;
57
 
58
                return retval;
59
        end function log2;
60
 
61
end package body pp_utilities;

powered by: WebSVN 2.1.0

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