Professional Documents
Culture Documents
net/publication/310970269
CITATIONS READS
0 1,194
3 authors:
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
Target assignment and path calculation for MIRADAS probe arms View project
All content following this page was uploaded by José María Gómez Cama on 28 November 2016.
Abstract—The VHDL 2008 standard provides the fixed point Where xhigh is the sign bit. If it is 0, the value represented
type, and the associated library. This library presents a small is positive. If not, the value is negative.
bug that makes that a number can have a different rounding As a result the number 6.5 will be represented as:
depending on its representation. The authors have found that
there is a small error in the definition of the resize function that
y = − 0 − 22 + 21 + 2−1
generates this incorrect behavior. A test is presented that shows = 6.5 (2)
the undesired behavior. Finally, a workaround is provided that
solves the problem while the new library is being prepared. or, expressed in binary:
x <= "000001101000";
I. I NTRODUCTION
While the value -0.125 can be represented as:
Fixed point arithmetic is highly used in image and signal
processing. It is simpler to implement in FPGAs or ASICs than x <= "111111111110";
its floating point counterpart, providing equivalent results in whose value can be calculated using the formula:
terms of precision at a reduced cost in terms of resources.
For this reason VHDL 2008 [1] has incorporated the fixed-
point package. This package provides the arithmetic operators y= − 27 − 26 + 25 + 4 3 2 1 0
2 + 2 + 2 + 2 + 2 +
−1 −2 −3 (3)
and functions necessary to work with these numbers. 2 +2 +2 = −0.125
The authors have been using this package during the last two The same number can also be represented in different ways
years. During this time, they have detected some mismatches depending on the range of bits used. The minimum number
between the results obtained using fixed-point arithmetic and of bits needed to represent the value 6.5 with an sfixed is 5
the expected ones that were calculated using floating-point bits:
numbers.
As a matter of fact, the number -0.125 could be rounded to signal x: sfixed (3 downto -1);
0.0 or -1.0 depending on the way it was represented using the x <= "01101";
fixed-point notation. For this reason, the code of the library While -0.125 only needs 2 bits:
was revised tracing the error to the resize function.
y = − 2−2 − 2−3 = −0.125
(4)
II. F IXED - POINT NOTATION
In VHDL 2008, the signed fixed point type is defined in the so it can be written as:
following way: signal x: sfixed (-2 downto -3);
type sfixed is array (INTEGER range <>) x <= "11";
of STD_ULOGIC; While the representation may differ if we use 12, 5 or 2
As a result, a sfixed number is declared as sfixed (high bits, we will expect to get the same result when applying
downto low), where high is the index of the most signifi- a mathematical function. This is not the case for the resize
cant bit, and low is the index of the least one. The following function included in the fixed point package. This can be seen
code shows an example: using the test described in the following section.
signal x: sfixed (7 downto -4);
III. T EST
Which represents a signed fixed point 12 bits wide (7 - (-
The error can be detected doing some simple operations
4) + 1), with 4 bits after the binary point. The bits of the
when using resize with rounding. If truncation is used, no
number can be indexed as xi . The sign is coded using two’s
error appears. The VHDL test code is:
complement. The value represented by the sfixed number can
be determined using the formula: library IEEE;
use IEEE.std_logic_1164.all;
high−1
!
high
X
i use IEEE.fixed_float_types.all;
y = − xhigh · 2 − xi · 2 (1) use IEEE.fixed_pkg.all;
i=low
use IEEE.math_real.all;
M. Carmona, D. Roma, J.M. Gomez are with the Department of Electronic use std.textio.all;
Engineering, Universitat de Barcelona, Barcelona, ES
J. M. Gomez is also with Institute of Cosmos Sciences, University of
Barcelona (IEEC-UB), Barcelona, Spain entity sfixed_resize is
Manuscript received October 19, 2016; revised November 20, 2016. end entity sfixed_resize;
2
body source code. This implies that this case can be easily
corrected.
V. C ONCLUSIONS
A bug has been detected in the resize function of the
VHDL-2008 Fixed point package. It gives different results
for the same number depending on its original representation.
A workaround function is presented that solves the problem
while the package is updated in the different VHDL compilers
and synthesizers.
ACKNOWLEDGMENT
This work has been funded by the Spanish MINECO
through project ESP2015-66494-R, including a percentage
from European FEDER funds.
R EFERENCES
[1] IEEE Std 1076-2008 - IEEE Standard VHDL Language Reference Man-
ual. IEEE, 2008.
[2] IEEE Std 754-2008 - IEEE Standard for Floating-Point Arithmetic.
IEEE, 2008.