From b4b9667def34e75a1324906d9b7cec45fa3b31b7 Mon Sep 17 00:00:00 2001 From: Cary R Date: Thu, 13 Nov 2008 16:06:57 -0800 Subject: [PATCH] Fix signed divide for words that match the machine word. There was an error when calculating the negative of a value that was the same width as the native machine word. This patch is similar to what was done in 0.9 to fix the problem there. --- vvp/arith.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/vvp/arith.cc b/vvp/arith.cc index 715ad9fb7..abb24a5c7 100644 --- a/vvp/arith.cc +++ b/vvp/arith.cc @@ -124,14 +124,18 @@ void vvp_arith_div::set(vvp_ipoint_t i, bool push, unsigned val, unsigned) unsigned sign_flip = 0; if (signed_flag_) { + unsigned long sign_mask = 0; + if (wid_ != 8*sizeof(unsigned long)) { + sign_mask = -1UL << wid_; + } if (a & (1UL << (wid_ - 1))) { - a ^= ~(-1UL << wid_); + a ^= ~sign_mask; a += 1; sign_flip += 1; } if (b & (1UL << (wid_ - 1))) { - b ^= ~(-1UL << wid_); + b ^= ~sign_mask; b += 1; sign_flip += 1; }