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.
This commit is contained in:
Cary R 2008-11-13 16:06:57 -08:00 committed by Stephen Williams
parent 5e401055e8
commit b4b9667def
1 changed files with 6 additions and 2 deletions

View File

@ -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;
}