-- The Potato Processor - A simple processor for FPGAs
|
-- The Potato Processor - A simple processor for FPGAs
|
-- (c) Kristian Klomsten Skordal 2014 <kristian.skordal@wafflemail.net>
|
-- (c) Kristian Klomsten Skordal 2014 <kristian.skordal@wafflemail.net>
|
-- Report bugs and issues on <https://github.com/skordal/potato/issues>
|
-- Report bugs and issues on <http://opencores.org/project,potato,bugtracker>
|
|
|
library ieee;
|
library ieee;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
|
|
use work.pp_types.all;
|
use work.pp_types.all;
|
use work.pp_constants.all;
|
use work.pp_constants.all;
|
|
|
package pp_utilities is
|
package pp_utilities is
|
|
|
--! Converts a boolean to an std_logic.
|
--! Converts a boolean to an std_logic.
|
function to_std_logic(input : in boolean) return std_logic;
|
function to_std_logic(input : in boolean) return std_logic;
|
|
|
-- Checks if a number is 2^n:
|
-- Checks if a number is 2^n:
|
function is_pow2(input : in natural) return boolean;
|
function is_pow2(input : in natural) return boolean;
|
|
|
--! Calculates log2 with integers.
|
--! Calculates log2 with integers.
|
function log2(input : in natural) return natural;
|
function log2(input : in natural) return natural;
|
|
|
end package pp_utilities;
|
end package pp_utilities;
|
|
|
package body pp_utilities is
|
package body pp_utilities is
|
|
|
function to_std_logic(input : in boolean) return std_logic is
|
function to_std_logic(input : in boolean) return std_logic is
|
begin
|
begin
|
if input then
|
if input then
|
return '1';
|
return '1';
|
else
|
else
|
return '0';
|
return '0';
|
end if;
|
end if;
|
end function to_std_logic;
|
end function to_std_logic;
|
|
|
function is_pow2(input : in natural) return boolean is
|
function is_pow2(input : in natural) return boolean is
|
variable c : natural := 1;
|
variable c : natural := 1;
|
begin
|
begin
|
for i in 0 to 31 loop
|
for i in 0 to 31 loop
|
if input = i then
|
if input = i then
|
return true;
|
return true;
|
end if;
|
end if;
|
|
|
c := c * 2;
|
c := c * 2;
|
end loop;
|
end loop;
|
|
|
return false;
|
return false;
|
end function is_pow2;
|
end function is_pow2;
|
|
|
function log2(input : in natural) return natural is
|
function log2(input : in natural) return natural is
|
variable retval : natural := 0;
|
variable retval : natural := 0;
|
variable temp : natural := input;
|
variable temp : natural := input;
|
begin
|
begin
|
while temp > 1 loop
|
while temp > 1 loop
|
retval := retval + 1;
|
retval := retval + 1;
|
temp := temp / 2;
|
temp := temp / 2;
|
end loop;
|
end loop;
|
|
|
return retval;
|
return retval;
|
end function log2;
|
end function log2;
|
|
|
end package body pp_utilities;
|
end package body pp_utilities;
|
|
|