Merge pull request #118 from antonblanchard/bus-pipeline
[microwatt.git] / utils.vhdl
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
4
5 package utils is
6
7 function log2(i : natural) return integer;
8 function ispow2(i : integer) return boolean;
9
10 end utils;
11
12 package body utils is
13
14 function log2(i : natural) return integer is
15 variable tmp : integer := i;
16 variable ret : integer := 0;
17 begin
18 while tmp > 1 loop
19 ret := ret + 1;
20 tmp := tmp / 2;
21 end loop;
22 return ret;
23 end function;
24
25 function ispow2(i : integer) return boolean is
26 begin
27 if to_integer(to_unsigned(i, 32) and to_unsigned(i - 1, 32)) = 0 then
28 return true;
29 else
30 return false;
31 end if;
32 end function;
33
34 end utils;
35