|
|
@ -5,6 +5,7 @@ use ieee.numeric_std.all;
|
|
|
|
package utils is
|
|
|
|
package utils is
|
|
|
|
|
|
|
|
|
|
|
|
function log2(i : natural) return integer;
|
|
|
|
function log2(i : natural) return integer;
|
|
|
|
|
|
|
|
function log2ceil(i : natural) return integer;
|
|
|
|
function ispow2(i : integer) return boolean;
|
|
|
|
function ispow2(i : integer) return boolean;
|
|
|
|
|
|
|
|
|
|
|
|
end utils;
|
|
|
|
end utils;
|
|
|
@ -22,6 +23,17 @@ package body utils is
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
end function;
|
|
|
|
end function;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function log2ceil(i : natural) return integer is
|
|
|
|
|
|
|
|
variable tmp : integer := i;
|
|
|
|
|
|
|
|
variable ret : integer := 0;
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
|
|
|
while tmp >= 1 loop
|
|
|
|
|
|
|
|
ret := ret + 1;
|
|
|
|
|
|
|
|
tmp := tmp / 2;
|
|
|
|
|
|
|
|
end loop;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
end function;
|
|
|
|
|
|
|
|
|
|
|
|
function ispow2(i : integer) return boolean is
|
|
|
|
function ispow2(i : integer) return boolean is
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
if to_integer(to_unsigned(i, 32) and to_unsigned(i - 1, 32)) = 0 then
|
|
|
|
if to_integer(to_unsigned(i, 32) and to_unsigned(i - 1, 32)) = 0 then
|
|
|
|