IEEE VHDL Floating-Point Package: Accuracy Audit
An exact-arithmetic audit finds rounding errors and simulator stops in IEEE VHDL floating-point routines, and tests a package-body patch.

IEEE VHDL Floating-Point Package: Accuracy Audit
What an Exact-Arithmetic Audit Found in IEEE's VHDL Packages
A standard package can compile cleanly, run on more than one simulator, and still give numerically wrong answers. That's the practical problem this audit looked at in the IEEE VHDL floating-point package ieee.float_pkg, plus its fixed-point counterpart ieee.fixed_pkg. The audit compared package results against an independent exact-arithmetic reference, including inputs chosen specifically to stress rounding, denormals, exponent limits, and signed zero.
The results matter, but they need careful framing. This is about a particular IEEE package body and the tested configurations - it's not a blanket claim that every VHDL design, or every arithmetic call, is wrong. Some operations match the reference on the test vectors; others miss often; and a small set can stop the simulator. A package-body patch was also tested on the same vectors, with no mismatches in the reported runs. Below is what was measured, where the failures come from, and how to reproduce the comparison before relying on a fix.
What the audit tested
The package under examination is ieee.float_pkg, backed by the IEEE float_generic_pkg implementation. The audit used the IEEE package body identified as revision 1220, a 5,712-line VHDL file. According to the source analysis, GHDL and NVC ship the same package-body bytes as the IEEE release source. Tests ran using GHDL 7.0.0-dev and NVC 1.23.1; for the vectors run in both, the simulators produced identical result files.
That agreement answers one question: whether the two simulators execute the tested package consistently. It does not tell you whether the returned bits are mathematically correct. To check correctness, the audit used exact.py. The reference model represents an operand as a sign and an integer fraction, computes the operation exactly, then rounds once into the requested floating-point format and rounding mode.
Why exact arithmetic is a useful baseline
Floating-point implementations often use guard bits - extra temporary precision kept during intermediate steps - so the final result rounds correctly. This can be an efficient strategy, but it only works if enough information survives up to the rounding step. If a remainder or discarded low bit vanishes before rounding, the final answer can differ from the correctly rounded one.
The reference model doesn't use the package under test as its own oracle. It also makes mismatches concrete: a result is marked wrong when it differs from the exact operation rounded to the target format using the requested rounding mode. Integer conversions whose mathematical result doesn't fit the requested integer type were excluded.
This still isn't a proof for every possible VHDL value. It's a reproducible differential test against a defined arithmetic model, supported by analysis of the implementation's source. When the input space is manageable, small-format exhaustive testing adds stronger coverage.
What operations and edge cases were included
The floating-point tests covered float16, float32, float64, and float128. Operations included addition, subtraction, multiplication, division, square root, multiply-accumulate, reciprocal, format resizing, integer conversions, scaling, and division by powers of two.
The test inputs were aimed at failure boundaries, not just "typical" values. The sets included:
- Denormal inputs and outputs, and values near the smallest representable magnitudes.
- Values near the largest exponent and transitions between exponent ranges.
- Exact halfway cases and fractions that round into the next exponent binade.
- Positive and negative zero, infinities, and cancellation.
- Multiple rounding styles: nearest, toward zero, toward negative infinity, and toward positive infinity.
That kind of boundary-focused testing is a good fit for arithmetic code. Random ordinary inputs can show general behavior, but boundary-directed cases are more likely to expose errors in normalization, sticky-bit handling, and overflow decisions.
Where the floating-point package goes wrong
This isn't just one isolated bug. The source analysis points to several patterns: exponent values narrowed before range checks, discarded remainder information, intermediate products truncated before addition, and special values routed through finite-number paths. Different operations and rounding styles fail in different ways.
Normalization and resizing can wrap exponents
In normalize, the exponent is resized to a narrower vector before the implementation decides whether the result should be treated as zero, denormal, normal, or infinity. Narrowing a signed exponent like this can effectively wrap it modulo the destination width.
For example, in the tested package, resizing a float64 value of 2-512 to float32 returns 1.0, and resizing 2600 becomes 288 instead of overflowing to infinity.
Some wrapped exponents produce a shift count outside the fraction range, and that's enough to stop the simulator. In the reported float64-to-float32 tests, very small inputs triggered this behavior. The same path also mishandles overflow and underflow across rounding modes: oversized results become infinity regardless of direction, and undersized results become zero even when directed rounding should produce the largest or smallest representable value.
The core engineering lesson is straightforward: classification (zero/denormal/normal/infinity) has to happen before narrowing an exponent. A conversion that looks harmless for "normal" values can silently change meaning for boundary values.
Division, reciprocal, and square root lose rounding information
The division and reciprocal routines pass a constant one as the sticky bit to rounding. A sticky bit should indicate whether any discarded remainder is nonzero. If it's treated as always set, an exact quotient can look inexact. Depending on the rounding mode, that can push results the wrong way or change how exact halfway cases are resolved.
Reciprocal has an additional issue with exponent width. Its result exponent is calculated as -e - 3 but stored in a vector with the width of the input exponent. At the top binade, that result doesn't fit. In the tested float32 package, reciprocal of 2127 returns infinity; in float64, reciprocal of 21023 does the same, even though the mathematical reciprocals are finite. The analysis also found reciprocal can produce the wrong sign for some special values, including 1/-0 and 1/-infinity.
Square root uses a fixed number of Newton iterations in truncated fixed-point arithmetic, then rounds without a sticky bit. For normal inputs, the errors reported were often about one unit in the last place; denormal inputs can be worse because the starting estimate isn't close enough for the iteration count to converge well. One example: sqrt(2^-149) returns roughly eleven times the correct float32 result.
Multiply-accumulate and conversions expose truncation errors
The multiply-accumulate routine truncates the product to the width of one operand before adding the third value. That undercuts what people expect from a fused multiply-add: keeping the product's low bits until the sum is formed and rounded once. When the addend cancels most of the product, the discarded bits can end up determining the final answer. The audit also found sign and infinity-handling problems in this routine.
Integer conversions have a similar information-loss problem. The implementation keeps three bits below the integer boundary, but it doesn't consistently collect the remaining discarded bits into a sticky bit. With directed rounding, that means the rounding step may inspect only part of the information below the integer. For example, converting 0.50000006 to a signed integer can produce zero, and converting 2.25 with rounding toward positive infinity can produce 2 instead of 3.
Other reported issues include exact cancellation returning positive zero even when rounding toward negative infinity requires negative zero, plus narrowing resize changing negative zero to positive zero. These edge cases might not show up much in application outputs, but signed zero and directed rounding are real observable parts of floating-point behavior - not just "cosmetic" ones.
What the measurements do and do not prove
For the package default settings - round to nearest, three guard bits, and denormal numbers enabled - the audit ran 10,000 targeted calls per operation, format, and rounding style where noted. For float32, totals were 81,068 wrong results and 272 simulator stops across 859,771 calls. Float64 had 86,081 wrong results and 445 stops across 857,234 calls. Float16 and float128 also showed substantial mismatch counts in their tested sets.
Those totals don't mean every operation failed equally. Float32 addition and subtraction had no mismatches in the 10,000 round-to-nearest cases each, while multiply-accumulate had 2,671 wrong results in 10,000. Division had 27 wrong round-to-nearest results, but thousands under directed rounding. Square root had 735 round-to-nearest mismatches. Resizing to a narrower format produced wrong values too, and in some cases stopped the simulator.
Exhaustive small formats change the confidence level
For a seven-bit format with three exponent bits and three fraction bits, every operand, pair, and multiply-accumulate triple was tested. The shipped package had 1,271,619 wrong results in 8,692,326 comparisons. For a ten-bit format, exhaustive operand and pair testing found 883,716 wrong results in 17,340,682 comparisons. In the seven-bit format, multiply-accumulate in round-to-nearest was wrong for 243,520 of 2,097,152 input triples.
Exhaustive tests don't cover every standard format or every possible call signature. They do remove sampling uncertainty for the enumerated domains. Combined with source-level explanations and targeted full-width tests, they make a stronger case than a handful of hand-picked examples.
Interpret the results within their scope
These counts describe the tested package body, simulator versions, formats, parameter settings, and vectors. They shouldn't be read as a measured failure rate for a product. Real designs use different inputs and may never call the affected functions or rounding modes. Likewise, passing the tested vectors doesn't prove correctness for all operands.
The audit also compared its exact reference with the host machine's arithmetic for 99,135 float32 and float64 operations across addition, subtraction, multiplication, division, and square root in round-to-nearest; none differed. That's a useful cross-check of the reference for those cases, not a universal certification of the reference implementation.
One notable result is that GHDL and NVC produced identical files on the same vectors, including the same lines where simulation stopped. That points away from a simulator-specific glitch and toward shared package behavior. It still doesn't guarantee all simulator/package versions behave identically.
What the patch changes
The proposed float_generic_pkg-body.patch changes the package body only; it does not change declarations. The fixes track the failure mechanisms rather than trying to special-case particular examples:
- Normalize at full exponent width. Classify zero, denormal, normal, and infinity before narrowing the exponent, then apply the requested overflow/underflow behavior for the rounding mode.
- Preserve division remainder information. Compute the sticky bit from the actual remainder. Keep reciprocal's exponent wide enough and preserve signs for zero and infinity.
- Use integer square root with a remainder. Compute the significand root bit-by-bit and use the remainder to inform final rounding.
- Keep the full multiply-accumulate intermediate. Put the product and addend in a shared window, perform the add/subtract there, then round once. This restores fused behavior rather than rounding a truncated product early.
- Retain discarded bits during conversion. Carry relevant low bits and sticky information into rounding, including for directed rounding.
- Handle signed zero and special scaling cases explicitly. Preserve negative zero when resizing, keep zero and infinity unchanged from scaling, and avoid losing denormal rounding information.
On the reported comparison vectors, the patched body had zero wrong results and zero stops across 3,439,564 calls in four formats. It also had zero mismatches in the exhaustive seven-bit and ten-bit cases, the float16 one-operand tests, and the 25-call example testbench. Those results are strong evidence for the patch on the tested cases, but they're still not a substitute for review and validation against a design's own usage.
Guard bits and denormal settings still matter
The package exposes guard-bit and denormal settings, so the patch was tested under multiple configurations. With three or four guard bits, all 258,075 tested calls matched the reference in the patched package where the shipped package differed. With two guard bits, 112 addition/subtraction cases were wrong in both versions; with one guard bit, 2,194 addition/subtraction/multiplication cases were wrong in both.
That's an important limitation, not a "patch failure." Too few guard bits can make correct rounding impossible for some operations because the intermediate representation has already thrown away the information you need. With no guard bits, patched square root, multiply-accumulate, and reciprocal often return exact values cut off toward zero instead of properly rounded values. A logic fix can't recreate precision that the configured precision never retained.
For denormalize false, the audit compares against the numbers defined by that setting, where an exponent field of zero represents another binade with a leading one. Results for that configuration shouldn't be judged using denormal-enabled expectations.
The fixed-point package has a separate division defect
The same audit examined ieee.fixed_pkg. In 751,418 calls across the tested small signed and unsigned domains, addition, subtraction, multiplication, remainder, modulo, comparisons, carry, resizing, conversions, scaling, unary minus, and absolute value all matched the reference. Division did not.
The division routines carry the quotient only through the configured guard bits. The rounding step sees those bits, but not whether a remainder remains. That means values just above or below a tie can be treated like an exact tie. For example, 0.125 / 1.875 in ufixed(3 downto -3) returns 0.0625 even though the quotient is about 0.0667 and the nearest representable result is 0.0703.
The proposed fixed-point patch adds a bit derived from the division remainder. For negative signed division, it also adjusts an inexact quotient downward before resize applies rounding or truncation. In the reported 751,418-call run, the patch reduced 41,026 mismatches to zero. This is a distinct fix for a distinct arithmetic path; fixing floating-point division doesn't automatically fix fixed-point division.
How to reproduce the audit
The tests require GHDL or NVC, Python 3.9 or later, and the IEEE package declaration, package body, and float_pkg source files. The audit scripts compile the shipped package and patched package separately, then run each testbench against both. This avoids changing the package declaration just to test a body-level correction.
Start with the small, quick run
A short run is useful for checking the toolchain setup and package paths. The script accepts a simulator name, the path to the IEEE source directory, and a vector count. For example:
sh run.sh ghdl /path/to/ieee 100
The reported 100-vector run completed 34,440 operations: the shipped package had 3,696 wrong results and eight stops, while the patched package had zero wrong results and zero stops. The same result was reported with both GHDL and NVC.
For a larger run, use NVC with 10,000 vectors per operation, format, and rounding style:
sh run.sh nvc /path/to/ieee 10000
NVC was faster on the large test set described in the audit, particularly for some fixed-point-style internal work in square root and division at float128. Runtime will depend on your machine and simulator build.
Generate and check vectors separately
The reference script can generate targeted vectors for the listed format configurations, exhaust a small format, and compare simulator output against expected results:
python3 exact.py gen 2026 10000 5,10 8,23 11,52 15,112 > vectors.txt
python3 exact.py all 3,3 > vectors.txt
python3 exact.py check vectors.txt results.txt
The first command generates 10,000 vectors for each requested format configuration. The second enumerates every operand in a small format. In a production review, keep the generated inputs, simulator outputs, tool versions, package revision, and compile options together. Without those details, it's hard to reproduce a mismatch count or compare it later.
Decide whether to use a patched body
Don't replace a standard package body in a production flow based only on a benchmark table. First verify which package file your simulator actually compiles, whether the tested defect applies to your functions and formats, and whether the patch has been reviewed against the exact version you're using. Then run your own regression suite under the same rounding and denormal settings as the design.
A practical sequence:
- Identify the arithmetic operations, formats, rounding styles, and special values used by the design.
- Confirm the source revision and simulator/package actually selected during compilation.
- Reproduce the relevant test cases with an independent expected-value path.
- Review the body-level changes and rerun design-level regression tests.
- Record the modified package and toolchain so the behavior stays auditable.
The audit also lists areas it didn't test, including comparisons, text input/output, real/fixed conversions, mixed-format calls, and some other functions. It notes that a VHDL-93 package carries corresponding lines but was not run. Treat those as open scope, not as implicitly covered by the results above.
Conclusion
The core takeaway is simple: matching simulator outputs isn't the same as correct arithmetic. In this audit, an independent exact reference, targeted boundary vectors, exhaustive small-format tests, and source inspection exposed failures in both IEEE floating-point and fixed-point package bodies. The proposed body patches removed mismatches on the reported tests, while reduced guard-bit configurations still showed the limits of available intermediate precision.
For a real design, the right move isn't to assume everything is broken or to adopt a patch blindly. Identify the exact package revision, map the findings to the operations and settings you use, and validate against an independent reference plus your own regression suite. That turns a broad audit into a defensible engineering decision.