aboutsummaryrefslogtreecommitdiffstats
path: root/libraries/ieee/math_real-body.vhdl
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ieee/math_real-body.vhdl')
-rw-r--r--libraries/ieee/math_real-body.vhdl230
1 files changed, 108 insertions, 122 deletions
diff --git a/libraries/ieee/math_real-body.vhdl b/libraries/ieee/math_real-body.vhdl
index c20aab7c9..2386f82fa 100644
--- a/libraries/ieee/math_real-body.vhdl
+++ b/libraries/ieee/math_real-body.vhdl
@@ -1,53 +1,52 @@
-------------------------------------------------------------------------
+-- -----------------------------------------------------------------
+--
+-- Copyright 2019 IEEE P1076 WG Authors
+--
+-- See the LICENSE file distributed with this work for copyright and
+-- licensing information and the AUTHORS file.
+--
+-- This file to you under the Apache License, Version 2.0 (the "License").
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+-- implied. See the License for the specific language governing
+-- permissions and limitations under the License.
--
--- Copyright 1996 by IEEE. All rights reserved.
-
--- This source file is an informative part of IEEE Std 1076.2-1996, IEEE Standard
--- VHDL Mathematical Packages. This source file may not be copied, sold, or
--- included with software that is sold without written permission from the IEEE
--- Standards Department. This source file may be used to implement this standard
--- and may be distributed in compiled form in any manner so long as the
--- compiled form does not allow direct decompilation of the original source file.
--- This source file may be copied for individual use between licensed users.
--- This source file is provided on an AS IS basis. The IEEE disclaims ANY
--- WARRANTY EXPRESS OR IMPLIED INCLUDING ANY WARRANTY OF MERCHANTABILITY
--- AND FITNESS FOR USE FOR A PARTICULAR PURPOSE. The user of the source
--- file shall indemnify and hold IEEE harmless from any damages or liability
--- arising out of the use thereof.
-
---
--- Title: Standard VHDL Mathematical Packages (IEEE Std 1076.2-1996,
--- MATH_REAL)
---
--- Library: This package shall be compiled into a library
--- symbolically named IEEE.
---
--- Developers: IEEE DASC VHDL Mathematical Packages Working Group
---
--- Purpose: This package body is a nonnormative implementation of the
--- functionality defined in the MATH_REAL package declaration.
---
--- Limitation: The values generated by the functions in this package may
--- vary from platform to platform, and the precision of results
--- is only guaranteed to be the minimum required by IEEE Std 1076
--- -1993.
---
--- Notes:
--- The "package declaration" defines the types, subtypes, and
--- declarations of MATH_REAL.
--- The standard mathematical definition and conventional meaning
--- of the mathematical functions that are part of this standard
--- represent the formal semantics of the implementation of the
--- MATH_REAL package declaration. The purpose of the MATH_REAL
--- package body is to clarify such semantics and provide a
--- guideline for implementations to verify their implementation
--- of MATH_REAL. Tool developers may choose to implement
--- the package body in the most efficient manner available to them.
---
--- -----------------------------------------------------------------------------
--- Version : 1.5
--- Date : 24 July 1996
--- -----------------------------------------------------------------------------
+-- Title : Standard VHDL Mathematical Packages
+-- : (MATH_REAL package body)
+-- :
+-- Library : This package shall be compiled into a library
+-- : symbolically named IEEE.
+-- :
+-- Developers: IEEE DASC VHDL Mathematical Packages Working Group
+-- :
+-- Purpose : This package defines a standard for designers to use in
+-- : describing VHDL models that make use of common REAL
+-- : constants and common REAL elementary mathematical
+-- : functions.
+-- :
+-- Limitation: The values generated by the functions in this package
+-- : may vary from platform to platform, and the precision
+-- : of results is only guaranteed to be the minimum required
+-- : by IEEE Std 1076-2008.
+-- :
+-- Note : This package may be modified to include additional data
+-- : required by tools, but it must in no way change the
+-- : external interfaces or simulation behavior of the
+-- : description. It is permissible to add comments and/or
+-- : attributes to the package declarations, but not to change
+-- : or delete any original lines of the package declaration.
+-- : The package body may be changed only in accordance with
+-- : the terms of Clause 16 of this standard.
+-- :
+-- --------------------------------------------------------------------
+-- $Revision: 1220 $
+-- $Date: 2008-04-10 17:16:09 +0930 (Thu, 10 Apr 2008) $
+-- --------------------------------------------------------------------
package body MATH_REAL is
@@ -101,7 +100,7 @@ package body MATH_REAL is
FLAG := TRUE;
end loop;
return V;
- end POWER_OF_2_SERIES;
+ end function POWER_OF_2_SERIES;
constant TWO_AT_MINUS : REAL_VECTOR := POWER_OF_2_SERIES(
@@ -183,7 +182,7 @@ package body MATH_REAL is
end loop;
end if;
return REAL_ARR_3'(X, Y, Z);
- end CORDIC;
+ end function CORDIC;
--
-- Bodies for Global Mathematical Functions Start Here
@@ -201,7 +200,7 @@ package body MATH_REAL is
else
return 0.0;
end if;
- end SIGN;
+ end function SIGN;
function CEIL (X : in REAL ) return REAL is
-- Description:
@@ -240,7 +239,7 @@ package body MATH_REAL is
return RD;
end if;
end if;
- end CEIL;
+ end function CEIL;
function FLOOR (X : in REAL ) return REAL is
-- Description:
@@ -279,7 +278,7 @@ package body MATH_REAL is
return RD;
end if;
end if;
- end FLOOR;
+ end function FLOOR;
function ROUND (X : in REAL ) return REAL is
-- Description:
@@ -297,7 +296,7 @@ package body MATH_REAL is
else
return 0.0;
end if;
- end ROUND;
+ end function ROUND;
function TRUNC (X : in REAL ) return REAL is
-- Description:
@@ -315,7 +314,7 @@ package body MATH_REAL is
else
return 0.0;
end if;
- end TRUNC;
+ end function TRUNC;
@@ -326,8 +325,8 @@ package body MATH_REAL is
-- Notes:
-- a) Returns 0.0 on error
- variable XNEGATIVE : BOOLEAN := X < 0.0;
- variable YNEGATIVE : BOOLEAN := Y < 0.0;
+ constant XNEGATIVE : BOOLEAN := X < 0.0;
+ constant YNEGATIVE : BOOLEAN := Y < 0.0;
variable VALUE : REAL;
begin
-- Check validity of input arguments
@@ -354,7 +353,7 @@ package body MATH_REAL is
end if;
return VALUE;
- end "MOD";
+ end function "MOD";
function REALMAX (X, Y : in REAL ) return REAL is
@@ -369,7 +368,7 @@ package body MATH_REAL is
else
return Y;
end if;
- end REALMAX;
+ end function REALMAX;
function REALMIN (X, Y : in REAL ) return REAL is
-- Description:
@@ -383,7 +382,7 @@ package body MATH_REAL is
else
return Y;
end if;
- end REALMIN;
+ end function REALMIN;
procedure UNIFORM(variable SEED1,SEED2:inout POSITIVE;variable X:out REAL)
@@ -438,7 +437,7 @@ package body MATH_REAL is
SEED1 := POSITIVE'(TSEED1);
SEED2 := POSITIVE'(TSEED2);
X := REAL(Z)*4.656613e-10;
- end UNIFORM;
+ end procedure UNIFORM;
@@ -490,7 +489,7 @@ package body MATH_REAL is
COUNT := COUNT + 1;
end loop;
return NEWVAL;
- end SQRT;
+ end function SQRT;
function CBRT (X : in REAL ) return REAL is
-- Description:
@@ -503,7 +502,7 @@ package body MATH_REAL is
variable INIVAL: REAL;
variable XLOCAL : REAL := X;
- variable NEGATIVE : BOOLEAN := X < 0.0;
+ constant NEGATIVE : BOOLEAN := X < 0.0;
variable OLDVAL : REAL ;
variable NEWVAL : REAL ;
variable COUNT : INTEGER := 1;
@@ -545,7 +544,7 @@ package body MATH_REAL is
end if;
return NEWVAL;
- end CBRT;
+ end function CBRT;
function "**" (X : in INTEGER; Y : in REAL) return REAL is
-- Description:
@@ -588,7 +587,7 @@ package body MATH_REAL is
-- Get value for general case
return EXP (Y * LOG (REAL(X)));
- end "**";
+ end function "**";
function "**" (X : in REAL; Y : in REAL) return REAL is
-- Description:
@@ -631,7 +630,7 @@ package body MATH_REAL is
-- Get value for general case
return EXP (Y * LOG (X));
- end "**";
+ end function "**";
function EXP (X : in REAL ) return REAL is
-- Description:
@@ -649,7 +648,7 @@ package body MATH_REAL is
--
constant EPS : REAL := BASE_EPS*BASE_EPS*BASE_EPS;-- Precision criteria
- variable RECIPROCAL: BOOLEAN := X < 0.0;-- Check sign of argument
+ constant RECIPROCAL: BOOLEAN := X < 0.0;-- Check sign of argument
variable XLOCAL : REAL := ABS(X); -- Use positive value
variable OLDVAL: REAL ;
variable COUNT: INTEGER ;
@@ -733,7 +732,7 @@ package body MATH_REAL is
end if;
return NEWVAL;
- end EXP;
+ end function EXP;
--
@@ -767,7 +766,7 @@ package body MATH_REAL is
N := N -1;
end loop;
return N;
- end ILOGB;
+ end function ILOGB;
function LDEXP(X: in REAL; N: in INTEGER) RETURN REAL IS
-- Description:
@@ -776,7 +775,7 @@ package body MATH_REAL is
-- None
begin
return X*(2.0 ** N);
- end LDEXP;
+ end function LDEXP;
function LOG (X : in REAL ) return REAL IS
-- Description:
@@ -796,11 +795,7 @@ package body MATH_REAL is
-- 2. Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
- -- 3. All advertising materials mentioning features or use of this
- -- software must display the following acknowledgement:
- -- This product includes software developed by the University of
- -- California, Berkeley and its contributors.
- -- 4. Neither the name of the University nor the names of its
+ -- 3. Neither the name of the University nor the names of its
-- contributors may be used to endorse or promote products derived
-- from this software without specific prior written permission.
--
@@ -1103,8 +1098,6 @@ package body MATH_REAL is
variable M, J:INTEGER;
variable F1, F2, G, Q, U, U2, V: REAL;
- variable ZERO: REAL := 0.0;--Made variable so no constant folding occurs
- variable ONE: REAL := 1.0; --Made variable so no constant folding occurs
-- double logb(), ldexp();
@@ -1171,7 +1164,7 @@ package body MATH_REAL is
U2 := (U2 + LOGF_TAIL(J)) + Q; -- Tiny
U2 := U2 + LOGF_TAIL(N)*REAL(M);
return (U1 + U2);
- end LOG;
+ end function LOG;
function LOG2 (X: in REAL) return REAL is
@@ -1199,7 +1192,7 @@ package body MATH_REAL is
-- Compute value for general case
return ( MATH_LOG2_OF_E*LOG(X) );
- end LOG2;
+ end function LOG2;
function LOG10 (X: in REAL) return REAL is
@@ -1227,7 +1220,7 @@ package body MATH_REAL is
-- Compute value for general case
return ( MATH_LOG10_OF_E*LOG(X) );
- end LOG10;
+ end function LOG10;
function LOG (X: in REAL; BASE: in REAL) return REAL is
@@ -1262,7 +1255,7 @@ package body MATH_REAL is
-- Compute value for general case
return ( LOG(X)/LOG(BASE));
- end LOG;
+ end function LOG;
function SIN (X : in REAL ) return REAL is
@@ -1280,7 +1273,7 @@ package body MATH_REAL is
constant EPS : REAL := BASE_EPS*BASE_EPS; -- Convergence criteria
variable N : INTEGER;
- variable NEGATIVE : BOOLEAN := X < 0.0;
+ constant NEGATIVE : BOOLEAN := X < 0.0;
variable XLOCAL : REAL := ABS(X) ;
variable VALUE: REAL;
variable TEMP : REAL;
@@ -1293,10 +1286,8 @@ package body MATH_REAL is
end if;
if XLOCAL < 0.0 then
- assert FALSE
- report "XLOCAL <= 0.0 after reduction in SIN(X)"
- severity ERROR;
- XLOCAL := -XLOCAL;
+ -- adjust for rounding error
+ XLOCAL := 0.0;
end if;
-- Compute value for special cases
@@ -1413,7 +1404,7 @@ package body MATH_REAL is
-- Compute value for general cases
if ((XLOCAL < MATH_PI_OVER_2 ) and (XLOCAL > 0.0)) then
- VALUE:= CORDIC( KC, 0.0, x, 27, ROTATION)(1);
+ VALUE:= CORDIC( KC, 0.0, X, 27, ROTATION)(1);
end if;
N := INTEGER ( FLOOR(XLOCAL/MATH_PI_OVER_2));
@@ -1435,7 +1426,7 @@ package body MATH_REAL is
else
return VALUE;
end if;
- end SIN;
+ end function SIN;
function COS (X : in REAL) return REAL is
@@ -1452,7 +1443,6 @@ package body MATH_REAL is
constant EPS : REAL := BASE_EPS*BASE_EPS;
variable XLOCAL : REAL := ABS(X);
- variable VALUE: REAL;
variable TEMP : REAL;
begin
@@ -1463,10 +1453,8 @@ package body MATH_REAL is
end if;
if XLOCAL < 0.0 then
- assert FALSE
- report "XLOCAL <= 0.0 after reduction in COS(X)"
- severity ERROR;
- XLOCAL := -XLOCAL;
+ -- adjust for rounding error
+ XLOCAL := 0.0;
end if;
-- Compute value for special cases
@@ -1511,7 +1499,7 @@ package body MATH_REAL is
-- Compute value for general cases
return SIN(MATH_PI_OVER_2 - XLOCAL);
- end COS;
+ end function COS;
function TAN (X : in REAL) return REAL is
-- Description:
@@ -1522,7 +1510,7 @@ package body MATH_REAL is
-- c) Returns REAL'LOW on error if X < 0.0
-- d) Returns REAL'HIGH on error if X > 0.0
- variable NEGATIVE : BOOLEAN := X < 0.0;
+ constant NEGATIVE : BOOLEAN := X < 0.0;
variable XLOCAL : REAL := ABS(X) ;
variable VALUE: REAL;
variable TEMP : REAL;
@@ -1535,10 +1523,8 @@ package body MATH_REAL is
end if;
if XLOCAL < 0.0 then
- assert FALSE
- report "XLOCAL <= 0.0 after reduction in TAN(X)"
- severity ERROR;
- XLOCAL := -XLOCAL;
+ -- adjust for rounding error
+ XLOCAL := 0.0;
end if;
-- Check validity of argument
@@ -1576,7 +1562,7 @@ package body MATH_REAL is
else
return VALUE;
end if;
- end TAN;
+ end function TAN;
function ARCSIN (X : in REAL ) return REAL is
-- Description:
@@ -1585,8 +1571,8 @@ package body MATH_REAL is
-- a) ARCSIN(-X) = -ARCSIN(X)
-- b) Returns X on error
- variable NEGATIVE : BOOLEAN := X < 0.0;
- variable XLOCAL : REAL := ABS(X);
+ constant NEGATIVE : BOOLEAN := X < 0.0;
+ constant XLOCAL : REAL := ABS(X);
variable VALUE : REAL;
begin
@@ -1621,7 +1607,7 @@ package body MATH_REAL is
end if;
return VALUE;
- end ARCSIN;
+ end function ARCSIN;
function ARCCOS (X : in REAL) return REAL is
-- Description:
@@ -1630,8 +1616,8 @@ package body MATH_REAL is
-- a) ARCCOS(-X) = MATH_PI - ARCCOS(X)
-- b) Returns X on error
- variable NEGATIVE : BOOLEAN := X < 0.0;
- variable XLOCAL : REAL := ABS(X);
+ constant NEGATIVE : BOOLEAN := X < 0.0;
+ constant XLOCAL : REAL := ABS(X);
variable VALUE : REAL;
begin
@@ -1665,7 +1651,7 @@ package body MATH_REAL is
end if;
return VALUE;
- end ARCCOS;
+ end function ARCCOS;
function ARCTAN (Y : in REAL) return REAL is
@@ -1678,7 +1664,7 @@ package body MATH_REAL is
constant EPS : REAL := BASE_EPS*BASE_EPS*BASE_EPS;
- variable NEGATIVE : BOOLEAN := Y < 0.0;
+ constant NEGATIVE : BOOLEAN := Y < 0.0;
variable RECIPROCAL : BOOLEAN;
variable YLOCAL : REAL := ABS(Y);
variable VALUE : REAL;
@@ -1733,7 +1719,7 @@ package body MATH_REAL is
end if;
return VALUE;
- end ARCTAN;
+ end function ARCTAN;
function ARCTAN (Y : in REAL; X : in REAL) return REAL is
@@ -1786,7 +1772,7 @@ package body MATH_REAL is
end if;
return VALUE;
- end ARCTAN;
+ end function ARCTAN;
function SINH (X : in REAL) return REAL is
@@ -1796,8 +1782,8 @@ package body MATH_REAL is
-- a) Returns (EXP(X) - EXP(-X))/2.0
-- b) SINH(-X) = SINH(X)
- variable NEGATIVE : BOOLEAN := X < 0.0;
- variable XLOCAL : REAL := ABS(X);
+ constant NEGATIVE : BOOLEAN := X < 0.0;
+ constant XLOCAL : REAL := ABS(X);
variable TEMP : REAL;
variable VALUE : REAL;
@@ -1816,7 +1802,7 @@ package body MATH_REAL is
end if;
return VALUE;
- end SINH;
+ end function SINH;
function COSH (X : in REAL) return REAL is
-- Description:
@@ -1825,7 +1811,7 @@ package body MATH_REAL is
-- a) Returns (EXP(X) + EXP(-X))/2.0
-- b) COSH(-X) = COSH(X)
- variable XLOCAL : REAL := ABS(X);
+ constant XLOCAL : REAL := ABS(X);
variable TEMP : REAL;
variable VALUE : REAL;
begin
@@ -1840,7 +1826,7 @@ package body MATH_REAL is
VALUE := (TEMP + 1.0/TEMP)*0.5;
return VALUE;
- end COSH;
+ end function COSH;
function TANH (X : in REAL) return REAL is
-- Description:
@@ -1849,8 +1835,8 @@ package body MATH_REAL is
-- a) Returns (EXP(X) - EXP(-X))/(EXP(X) + EXP(-X))
-- b) TANH(-X) = -TANH(X)
- variable NEGATIVE : BOOLEAN := X < 0.0;
- variable XLOCAL : REAL := ABS(X);
+ constant NEGATIVE : BOOLEAN := X < 0.0;
+ constant XLOCAL : REAL := ABS(X);
variable TEMP : REAL;
variable VALUE : REAL;
@@ -1869,7 +1855,7 @@ package body MATH_REAL is
else
return VALUE;
end if;
- end TANH;
+ end function TANH;
function ARCSINH (X : in REAL) return REAL is
-- Description:
@@ -1885,7 +1871,7 @@ package body MATH_REAL is
-- Compute value for general cases
return ( LOG( X + SQRT( X*X + 1.0)) );
- end ARCSINH;
+ end function ARCSINH;
@@ -1912,7 +1898,7 @@ package body MATH_REAL is
-- Compute value for general cases
return ( LOG( X + SQRT( X*X - 1.0)));
- end ARCCOSH;
+ end function ARCCOSH;
function ARCTANH (X : in REAL) return REAL is
-- Description:
@@ -1936,6 +1922,6 @@ package body MATH_REAL is
-- Compute value for general cases
return( 0.5*LOG( (1.0+X)/(1.0-X) ) );
- end ARCTANH;
+ end function ARCTANH;
-end MATH_REAL;
+end package body MATH_REAL;