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.
\r
15 function log2c(constant value : in integer) return integer;
\r
16 -- Returns the maximum of the two operands
\r
17 function max(constant value1, value2 : in integer) return integer;
\r
18 -- Returns the maximum of the three operands
\r
19 function max(constant value1, value2, value3 : in integer) return integer;
\r
22 package body math_pkg is
\r
23 function log2c(constant value : in integer) return integer is
\r
24 variable ret_value : integer;
\r
25 variable cur_value : integer;
\r
30 while cur_value < value loop
\r
31 ret_value := ret_value + 1;
\r
32 cur_value := cur_value * 2;
\r
37 function max(constant value1, value2 : in integer) return integer is
\r
38 variable ret_value : integer;
\r
40 if value1 > value2 then
\r
41 ret_value := value1;
\r
43 ret_value := value2;
\r
48 function max(constant value1, value2, value3 : in integer) return integer is
\r
50 return max(max(value1, value2), value3);
\r
52 end package body math_pkg;
\r