1 -------------------------------------------------------------------------
\r
3 -- Filename: math_pkg.vhd
\r
6 -- Short Description:
\r
7 -- ==================
\r
8 -- Utility Package defining often used mathematical functions
\r
10 -------------------------------------------------------------------------
\r
13 -- Calculates the logarithm dualis of the operand and rounds up
\r
14 -- the result to the next integer value.
15 function log2c(constant value : in integer) return integer;
\r
16 -- Returns the maximum of the two operands
17 function max(constant value1, value2 : in integer) return integer;
\r
18 -- Returns the maximum of the three operands
19 function max(constant value1, value2, value3 : in integer) return integer;
22 package body math_pkg is
23 function log2c(constant value : in integer) return integer is
24 variable ret_value : integer;
25 variable cur_value : integer;
30 while cur_value < value loop
31 ret_value := ret_value + 1;
32 cur_value := cur_value * 2;
37 function max(constant value1, value2 : in integer) return integer is
38 variable ret_value : integer;
40 if value1 > value2 then
48 function max(constant value1, value2, value3 : in integer) return integer is
50 return max(max(value1, value2), value3);
52 end package body math_pkg;