svlog: fix eval of clog2
Fix the evaluation of clog2 to return the appropriate values. Until now
the function would return the wrong number for powers of two, e.g. 3 for
clog2(4), instead of 2.
@@ -225,7 +225,12 @@ fn const_expr<'gcx>(
ValueKind::Int(ref arg) => arg,
_ => unreachable!(),
};
- Ok(cx.intern_value(make_int(arg_val.ty, arg_int.bits().into())))
+ let value: BigInt = if arg_int <= &num::zero() {
+ num::zero()
+ } else {
+ arg_int.bits().into()
+ };
+ Ok(cx.intern_value(make_int(arg_val.ty, value)))
}
hir::ExprKind::Builtin(hir::BuiltinCall::Bits(arg)) => {
let ty = cx.type_of(arg, env)?;
