math_pkg.vhd 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package math_pkg is
  2. -- calculates the logarithm dualis of the operand and rounds up
  3. -- the result to the next integer value.
  4. function log2c(constant value : in integer) return integer;
  5. -- returns the maximum of the two operands
  6. function max(constant value1, value2 : in integer) return integer;
  7. -- returns the maximum of the three operands
  8. function max(constant value1, value2, value3 : in integer) return integer;
  9. end package;
  10. package body math_pkg is
  11. function log2c(constant value : in integer) return integer is
  12. variable ret_value : integer;
  13. variable cur_value : integer;
  14. begin
  15. ret_value := 0;
  16. cur_value := 1;
  17. while cur_value < value loop
  18. ret_value := ret_value + 1;
  19. cur_value := cur_value * 2;
  20. end loop;
  21. return ret_value;
  22. end function;
  23. function max(constant value1, value2 : in integer) return integer is
  24. variable ret_value : integer;
  25. begin
  26. if value1 > value2 then
  27. ret_value := value1;
  28. else
  29. ret_value := value2;
  30. end if;
  31. return ret_value;
  32. end function;
  33. function max(constant value1, value2, value3 : in integer) return integer is
  34. begin
  35. return max(max(value1, value2), value3);
  36. end function;
  37. end package body;