Skip to content
Snippets Groups Projects
Commit 888ea716 authored by Dimitris Lampridis's avatar Dimitris Lampridis
Browse files

[hdl] clean-up log2 ceiling functions.

Reported by Olof Olof Kindgren (@olofk). See also merge request !4

.

Signed-off-by: default avatarDimitris Lampridis <dimitris.lampridis@cern.ch>
parent ba7bdc45
No related merge requests found
...@@ -27,8 +27,6 @@ library ieee; ...@@ -27,8 +27,6 @@ library ieee;
use ieee.std_logic_1164.all; use ieee.std_logic_1164.all;
use ieee.numeric_std.all; use ieee.numeric_std.all;
use work.genram_pkg.all;
package gencores_pkg is package gencores_pkg is
--============================================================================ --============================================================================
...@@ -342,7 +340,7 @@ package gencores_pkg is ...@@ -342,7 +340,7 @@ package gencores_pkg is
d_req_o : out std_logic_vector(g_num_inputs-1 downto 0); d_req_o : out std_logic_vector(g_num_inputs-1 downto 0);
q_o : out std_logic_vector(g_width-1 downto 0); q_o : out std_logic_vector(g_width-1 downto 0);
q_valid_o : out std_logic; q_valid_o : out std_logic;
q_input_id_o : out std_logic_vector(f_log2_size(g_num_inputs)-1 downto 0)); q_input_id_o : out std_logic_vector(f_log2_ceil(g_num_inputs)-1 downto 0));
end component; end component;
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
...@@ -838,17 +836,22 @@ package body gencores_pkg is ...@@ -838,17 +836,22 @@ package body gencores_pkg is
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
-- Returns log of 2 of a natural number -- Returns log of 2 of a natural number
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
function log2_ceil(N : natural) return positive is function f_log2_ceil(N : natural) return positive is
begin begin
if N <= 2 then if N <= 2 then
return 1; return 1;
elsif N mod 2 = 0 then elsif N mod 2 = 0 then
return 1 + log2_ceil(N/2); return 1 + f_log2_ceil(N/2);
else else
return 1 + log2_ceil((N+1)/2); return 1 + f_log2_ceil((N+1)/2);
end if; end if;
end; end;
-- kept for backwards compatibility
function log2_ceil(N : natural) return positive is
begin
return f_log2_ceil(N);
end;
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
-- Converts a boolean to natural integer (false -> 0, true -> 1) -- Converts a boolean to natural integer (false -> 0, true -> 1)
......
...@@ -248,14 +248,10 @@ end genram_pkg; ...@@ -248,14 +248,10 @@ end genram_pkg;
package body genram_pkg is package body genram_pkg is
-- kept for backwards compatibility
function f_log2_size (A : natural) return natural is function f_log2_size (A : natural) return natural is
begin begin
for I in 1 to 64 loop -- Works for up to 64 bits return f_log2_ceil(N);
if (2**I >= A) then
return(I);
end if;
end loop;
return(63);
end function f_log2_size; end function f_log2_size;
function f_gen_dummy_vec (val : std_logic; size : natural) return std_logic_vector is function f_gen_dummy_vec (val : std_logic; size : natural) return std_logic_vector is
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment