From 230d0f24defb343a783bafdd4b9360b8c93422f2 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Thu, 18 Oct 2007 21:09:12 -0700 Subject: [PATCH] Reformulate number-to-real on vvp code generator There have been reports in the field of number-to-real conversions doing bad things with the calculated mantissa. This patch eliminates a opssible portability problem by reworking the negating of negative mantissa values. Signed-off-by: Stephen Williams --- tgt-vvp/eval_real.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tgt-vvp/eval_real.c b/tgt-vvp/eval_real.c index b0176b0a7..832c398c2 100644 --- a/tgt-vvp/eval_real.c +++ b/tgt-vvp/eval_real.c @@ -121,9 +121,15 @@ static int draw_number_real(ivl_expr_t exp) /* If this is actually a negative number, then get the positive equivalent, and set the sign bit in the exponent - field. */ + field. + + To get the positive equivilent of mant we need to take the + negative of the mantissa (0-mant) but also be aware that + the bits may not have been as many bits as the width of the + mant variable. This would lead to spurious '1' bits in the + high bits of mant that are masked by ~((-1UL)<