Package: fixed_generic_pkg

Constants

Name Type Value Description
CopyRightNotice STRING "Copyright 2008 by IEEE. All rights reserved."

Types

Name Type Description
UNRESOLVED_ufixed array (INTEGER range <>) of STD_ULOGIC base Unsigned fixed point type, downto direction assumed
UNRESOLVED_sfixed array (INTEGER range <>) of STD_ULOGIC base Signed fixed point type, downto direction assumed

Functions

Description
This version of divide gives the user more control
ufixed(a downto b) / ufixed(c downto d) = ufixed(a-d downto b-c-1)

Description
This version of divide gives the user more control
sfixed(a downto b) / sfixed(c downto d) = sfixed(a-d+1 downto b-c)

Description
These functions return 1/X
1 / ufixed(a downto b) = ufixed(-b downto -a-1)

Description
1 / sfixed(a downto b) = sfixed(-b+1 downto -a)

Description
REM function
ufixed (a downto b) rem ufixed (c downto d)
= ufixed (minimum(a,c) downto minimum(b,d))

Description
sfixed (a downto b) rem sfixed (c downto d)
= sfixed (minimum(a,c) downto minimum(b,d))

Description
mod function
ufixed (a downto b) mod ufixed (c downto d)
= ufixed (minimum(a,c) downto minimum(b, d))

Description
sfixed (a downto b) mod sfixed (c downto d)
= sfixed (c downto minimum(b, d))

Description
Procedure for those who need an "accumulator" function.
add_carry (ufixed(a downto b), ufixed (c downto d))
= ufixed (maximum(a,c) downto minimum(b,d))

Description
add_carry (sfixed(a downto b), sfixed (c downto d))
= sfixed (maximum(a,c) downto minimum(b,d))

Description
Scales the result by a power of 2. Width of input = width of output with
the binary point moved.

Description
Overloads the default "maximum" and "minimum" function

Description
returns arg'low-1 if not found

Description
returns arg'high+1 if not found

Description

RESIZE Functions

resizes the number (larger or smaller)
The returned result will be ufixed (left_index downto right_index)
If "round_style" is fixed_round, then the result will be rounded.
If the MSB of the remainder is a "1" AND the LSB of the unrounded result
is a '1' or the lower bits of the remainder include a '1' then the result
will be increased by the smallest representable number for that type.
"overflow_style" can be fixed_saturate or fixed_wrap.
In saturate mode, if the number overflows then the largest possible
representable number is returned. If wrap mode, then the upper bits
of the number are truncated.

Description
"size_res" functions create the size of the output from the indices
of the "size_res" input. The actual value of "size_res" is not used.

Description
Note that in "wrap" mode the sign bit is not replicated. Thus the
resize of a negative number can have a positive result in wrap mode.

Description

Conversion Functions

integer (natural) to unsigned fixed point.
arguments are the upper and lower bounds of the number, thus
ufixed (7 downto -3) <= to_ufixed (int, 7, -3);

Description
real to unsigned fixed point

Description
unsigned to unsigned fixed point

Description
Performs a conversion. ufixed (arg'range) is returned

Description
unsigned fixed point to unsigned

Description
unsigned fixed point to unsigned

Description
unsigned fixed point to real

Description
unsigned fixed point to integer

Description
Integer to UNRESOLVED_sfixed

Description
Real to sfixed

Description
signed to sfixed

Description
signed to sfixed (output assumed to be size of signed input)

Description
Conversion from ufixed to sfixed

Description
signed fixed point to signed

Description
signed fixed point to signed

Description
signed fixed point to real

Description
signed fixed point to integer

Description
Because of the fairly complicated sizing rules in the fixed point
packages these functions are provided to compute the result ranges
Example:
signal uf1 : ufixed (3 downto -3);
signal uf2 : ufixed (4 downto -2);
signal uf1multuf2 : ufixed (ufixed_high (3, -3, '', 4, -2) downto ufixed_low (3, -3, '', 4, -2));
uf1multuf2 <= uf1 * uf2;
Valid characters: '+', '-', '*', '/', 'r' or 'R' (rem), 'm' or 'M' (mod),
'1' (reciprocal), 'a' or 'A' (abs), 'n' or 'N' (unary -)

Description
Same as above, but using the "size_res" input only for their ranges:
signal uf1multuf2 : ufixed (ufixed_high (uf1, '', uf2) downto ufixed_low (uf1, '', uf2));
uf1multuf2 <= uf1 * uf2;

Description
purpose: returns a saturated number

Description
purpose: returns a saturated number

Description

Translation Functions

maps meta-logical values

Description
maps meta-logical values

Description
straight vector conversion routines, needed for synthesis.
These functions are here so that a std_logic_vector can be
converted to and from sfixed and ufixed. Note that you can
not convert these vectors because of their negative index.

Description
As a concession to those who use a graphical DSP environment,
these functions take parameters in those tools format and create
fixed point numbers. These functions are designed to convert from
a std_logic_vector to the VHDL fixed point format using the conventions
of these packages. In a pure VHDL environment you should use the
"to_ufixed" and "to_sfixed" routines.
unsigned fixed point

Description
signed fixed point

Description
finding the bounds of a number. These functions can be used like this:
signal xxx : ufixed (7 downto -3);
-- Which is the same as "ufixed (UFix_high (11,3) downto UFix_low(11,3))"
signal yyy : ufixed (UFix_high (11, 3, "+", 11, 3)
downto UFix_low(11, 3, "+", 11, 3));
Where "11" is the width of xxx (xxx'length),
and 3 is the lower bound (abs (xxx'low))
In a pure VHDL environment use "ufixed_high" and "ufixed_low"

Description
Same as above but for signed fixed point. Note that the width
of a signed fixed point number ignores the sign bit, thus
width = sxxx'length-1

Description

string and textio Functions

purpose: writes fixed point into a line

Description
purpose: writes fixed point into a line

Description
octal read and write

Description
hex read and write

Description
purpose: writes fixed point into a line

Description
returns a string, useful for:
assert (x = y) report "error found " & to_string(x) severity error;

Description
From string functions allow you to convert a string into a fixed
point number. Example:
signal uf1 : ufixed (3 downto -3);
uf1 <= from_string ("0110.100", uf1'high, uf1'low); -- 6.5
The "." is optional in this syntax, however it exist and is
in the wrong location an error is produced. Overflow will
result in saturation.

Description
Octal and hex conversions work as follows:
uf1 <= from_hstring ("6.8", 3, -3); -- 6.5 (bottom zeros dropped)
uf1 <= from_ostring ("06.4", 3, -3); -- 6.5 (top zeros dropped)

Description
Same as above, "size_res" is used for it's range only.

Description
Direct conversion functions. Example:
signal uf1 : ufixed (3 downto -3);
uf1 <= from_string ("0110.100"); -- 6.5
In this case the "." is not optional, and the size of
the output must match exactly.

Description
Direct octal and hex conversion functions. In this case
the string lengths must match. Example:
signal sf1 := sfixed (5 downto -3);
sf1 <= from_ostring ("71.4") -- -6.5