- added MIN/MAX functions for integers

Committed on the Free edition of March Hare Software CVSNT Server.
Upgrade to CVS Suite for more features and support:
http://march-hare.com/cvsnt/


git-svn-id: http://moon:8086/svn/vhdl/trunk@810 cc03376c-175c-47c8-b038-4cd826a8556b
This commit is contained in:
2010-03-22 07:25:40 +00:00
parent 84fa08326f
commit c3c2cdfe2b
+39 -2
View File
@@ -1,5 +1,5 @@
-----------------------------------------------------------------------
-- $Header: /tmp/cvsroot/VHDL/lib/misc/utils_pkg.vhd,v 1.5 2010-02-09 10:16:36 Jens Exp $
-- $Header: /tmp/cvsroot/VHDL/lib/misc/utils_pkg.vhd,v 1.6 2010-03-22 07:25:40 Jens Exp $
-----------------------------------------------------------------------
library IEEE;
@@ -12,6 +12,9 @@ package utils_pkg is
-- Constants
-- Functions
function MIN (X, Y: INTEGER) return INTEGER;
function MAX (X, Y: INTEGER) return INTEGER;
function NextPowerOfTwo(x : real) return real;
function NextExpBaseTwo(x : real) return real;
function NextPowerOfTwo(x : natural) return natural;
@@ -28,28 +31,57 @@ end utils_pkg;
package body utils_pkg is
-------------------------------------------------------------
function MIN (X, Y: INTEGER) return INTEGER is
variable res : integer := X;
begin
if Y < X then
res := Y;
end if;
return res;
end MIN;
-------------------------------------------------------------
function MAX (X, Y: INTEGER) return INTEGER is
variable res : integer := X;
begin
if Y > X then
res := Y;
end if;
return res;
end MAX;
-------------------------------------------------------------
function NextExpBaseTwo(x : real) return real is
begin
return ceil(log2(x));
end NextExpBaseTwo;
-------------------------------------------------------------
function NextPowerOfTwo(x : real) return real is
begin
return 2.0**NextExpBaseTwo(x);
end NextPowerOfTwo;
-------------------------------------------------------------
function NextExpBaseTwo(x : natural) return natural is
begin
return natural(NextExpBaseTwo(real(x)));
end NextExpBaseTwo;
-------------------------------------------------------------
function NextPowerOfTwo(x : natural) return natural is
begin
return 2**NextExpBaseTwo(x);
end NextPowerOfTwo;
-------------------------------------------------------------
function GCD(a, b : natural) return natural is
variable aa : natural;
variable bb : natural;
@@ -68,6 +100,7 @@ package body utils_pkg is
end GCD;
-------------------------------------------------------------
function LCM(a, b : natural) return natural is
begin
@@ -75,6 +108,7 @@ package body utils_pkg is
end LCM;
-------------------------------------------------------------
function UTILS_PERIOD_NS(f_in_MHz : real) return real is
begin
@@ -82,6 +116,7 @@ package body utils_pkg is
end UTILS_PERIOD_NS;
-------------------------------------------------------------
function UTILS_FREQ_M(f_in_MHz, f_out_MHz : real) return natural is
variable f_in : natural;
variable f_out : natural;
@@ -110,6 +145,7 @@ package body utils_pkg is
end UTILS_FREQ_M;
-------------------------------------------------------------
function UTILS_FREQ_D(f_in_MHz, f_out_MHz : real) return natural is
variable f_in : natural;
variable f_out : natural;
@@ -138,7 +174,7 @@ package body utils_pkg is
end UTILS_FREQ_D;
-------------------------------------------------------------
function f_correct(f : real) return natural is
constant MAX_ITER : positive := 100;
constant MAX_ERR : real := 0.01;
@@ -154,6 +190,7 @@ package body utils_pkg is
end loop;
end f_correct;
-------------------------------------------------------------
end utils_pkg;