slightly modified history file
[hwmod.git] / debouncing / src / math_pkg.vhd
1 -------------------------------------------------------------------------\r
2 --\r
3 -- Filename: math_pkg.vhd\r
4 -- =========\r
5 --\r
6 -- Short Description:\r
7 -- ==================\r
8 --   Utility Package defining often used mathematical functions\r
9 --\r
10 -------------------------------------------------------------------------\r
11 \r
12 package math_pkg is\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
20 end math_pkg;\r
21 \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
26   begin\r
27     ret_value := 0;\r
28     cur_value := 1;\r
29     \r
30     while cur_value < value loop\r
31       ret_value := ret_value + 1;\r
32       cur_value := cur_value * 2;\r
33     end loop;\r
34     return ret_value;\r
35   end function log2c;\r
36   \r
37   function max(constant value1, value2 : in integer) return integer is\r
38     variable ret_value : integer;\r
39   begin\r
40     if value1 > value2 then\r
41       ret_value := value1;\r
42     else\r
43       ret_value := value2;\r
44     end if;\r
45     return ret_value;\r
46   end function max;\r
47   \r
48   function max(constant value1, value2, value3 : in integer) return integer is\r
49   begin\r
50     return max(max(value1, value2), value3);\r
51   end function max;\r
52  end package body math_pkg;\r
53