From 4cf8920e48844d544def3f062e0de2130d008228 Mon Sep 17 00:00:00 2001 From: Cary R Date: Tue, 5 Feb 2008 15:05:02 -0800 Subject: [PATCH] Fix trimming of unsigned verinum values. Incorrect trimming of unsigned verinum values was causing the compilers unsigned constant verinum pow function to give incorrect results. This patch restores the pow compile time optimization and fixes the trimming to always leave a single zero in the MSB. --- eval_tree.cc | 7 +------ verinum.cc | 15 +++++++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/eval_tree.cc b/eval_tree.cc index 13926ea0f..b5b198c1f 100644 --- a/eval_tree.cc +++ b/eval_tree.cc @@ -979,12 +979,7 @@ NetExpr* NetEBPow::eval_tree(int prune_to_width) verinum lval = lc->value(); verinum rval = rc->value(); - if (lc->has_sign() || rc->has_sign()) { - return new NetEConst( pow(lval,rval) ); - } else { - return 0; // For now force this to the runtime. - } - + return new NetEConst( pow(lval,rval) ); } /* diff --git a/verinum.cc b/verinum.cc index 27c32e224..6fa5ee75f 100644 --- a/verinum.cc +++ b/verinum.cc @@ -496,11 +496,15 @@ verinum trim_vnum(const verinum&that) } else { /* If the result is unsigned and has an indefinite - length, then trim off leading zeros. */ - tlen = 1; - for (unsigned idx = tlen ; idx < that.len() ; idx += 1) - if (that.get(idx) != verinum::V0) - tlen = idx+1; + length, then trim off all but one leading zero. */ + unsigned top = that.len()-1; + while ((top > 0) && (that.get(top) == verinum::V0)) + top -= 1; + tlen = top+2; + + /* This can only happen when the verinum is all zeros, + so make it a single bit wide. */ + if (that.get(top) == verinum::V0) tlen -= 1; } @@ -1211,4 +1215,3 @@ verinum::V operator ^ (verinum::V l, verinum::V r) return verinum::Vx; } -