| 1 |
3 |
jlechner |
-----------------------------------------------------------------------
|
| 2 |
|
|
-- This file is part of SCARTS.
|
| 3 |
|
|
--
|
| 4 |
|
|
-- SCARTS is free software: you can redistribute it and/or modify
|
| 5 |
|
|
-- it under the terms of the GNU General Public License as published by
|
| 6 |
|
|
-- the Free Software Foundation, either version 3 of the License, or
|
| 7 |
|
|
-- (at your option) any later version.
|
| 8 |
|
|
--
|
| 9 |
|
|
-- SCARTS is distributed in the hope that it will be useful,
|
| 10 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
|
|
-- GNU General Public License for more details.
|
| 13 |
|
|
--
|
| 14 |
|
|
-- You should have received a copy of the GNU General Public License
|
| 15 |
|
|
-- along with SCARTS. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
|
|
-----------------------------------------------------------------------
|
| 17 |
|
|
|
| 18 |
|
|
|
| 19 |
|
|
-------------------------------------------------------------------------
|
| 20 |
|
|
--
|
| 21 |
|
|
-- Filename: math_pkg.vhd
|
| 22 |
|
|
-- =========
|
| 23 |
|
|
--
|
| 24 |
|
|
-- Short Description:
|
| 25 |
|
|
-- ==================
|
| 26 |
|
|
-- Utility Package defining often used mathematical functions
|
| 27 |
|
|
--
|
| 28 |
|
|
-------------------------------------------------------------------------
|
| 29 |
|
|
|
| 30 |
|
|
package math_pkg is
|
| 31 |
|
|
-- Calculates the logarithm dualis of the operand and rounds up
|
| 32 |
|
|
-- the result to the next integer value.
|
| 33 |
|
|
function log2c(constant value : in integer) return integer;
|
| 34 |
|
|
-- Returns the maximum of the two operands
|
| 35 |
|
|
function max(constant value1, value2 : in integer) return integer;
|
| 36 |
|
|
-- Returns the maximum of the three operands
|
| 37 |
|
|
function max(constant value1, value2, value3 : in integer) return integer;
|
| 38 |
|
|
end math_pkg;
|
| 39 |
|
|
|
| 40 |
|
|
package body math_pkg is
|
| 41 |
|
|
function log2c(constant value : in integer) return integer is
|
| 42 |
|
|
variable ret_value : integer;
|
| 43 |
|
|
variable cur_value : integer;
|
| 44 |
|
|
begin
|
| 45 |
|
|
ret_value := 0;
|
| 46 |
|
|
cur_value := 1;
|
| 47 |
|
|
|
| 48 |
|
|
while cur_value < value loop
|
| 49 |
|
|
ret_value := ret_value + 1;
|
| 50 |
|
|
cur_value := cur_value * 2;
|
| 51 |
|
|
end loop;
|
| 52 |
|
|
return ret_value;
|
| 53 |
|
|
end function log2c;
|
| 54 |
|
|
|
| 55 |
|
|
function max(constant value1, value2 : in integer) return integer is
|
| 56 |
|
|
variable ret_value : integer;
|
| 57 |
|
|
begin
|
| 58 |
|
|
if value1 > value2 then
|
| 59 |
|
|
ret_value := value1;
|
| 60 |
|
|
else
|
| 61 |
|
|
ret_value := value2;
|
| 62 |
|
|
end if;
|
| 63 |
|
|
return ret_value;
|
| 64 |
|
|
end function max;
|
| 65 |
|
|
|
| 66 |
|
|
function max(constant value1, value2, value3 : in integer) return integer is
|
| 67 |
|
|
begin
|
| 68 |
|
|
return max(max(value1, value2), value3);
|
| 69 |
|
|
end function max;
|
| 70 |
|
|
end package body math_pkg;
|
| 71 |
|
|
|