The current log2ceil implementation fails in the range of (2**30 + 1 to positive'high) since the internal tmp variable is multiplied by 2 before comparison.
My testbench:
library ieee;
use ieee.std_logic_1164.all;
entity log2ceil_test is
end entity;
architecture tb of log2ceil_test is
function log2ceil(arg : positive) return natural is
variable tmp : positive := 2;
variable log : natural := 1;
begin
if arg = 1 then
return 0;
end if;
while arg > tmp loop
tmp := tmp * 2;
log := log + 1;
end loop;
return log;
end function;
begin
stim : process
begin
report "2**30-1";
assert log2ceil(2 ** 30 - 1) = 30 ;
report "2**30";
assert log2ceil(2 ** 30) = 30 ;
report "2**30+1";
assert log2ceil(2 ** 30 + 1) = 31 ;
report "2**31-1";
assert log2ceil(positive'high) = 31 ;
wait;
end process;
end architecture;
The current log2ceil implementation fails in the range of (2**30 + 1 to positive'high) since the internal tmp variable is multiplied by 2 before comparison.
My testbench: