From 52dc397a5085c360b6ac2e9538f96ba3e7956113 Mon Sep 17 00:00:00 2001 From: Charlotte Date: Wed, 28 Jun 2023 11:51:19 +1000 Subject: [PATCH] cxxrtl: don't use signed divide with unsigned/pos values Incorrect for unsigned, wasted effort for positive signed. --- backends/cxxrtl/cxxrtl.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backends/cxxrtl/cxxrtl.h b/backends/cxxrtl/cxxrtl.h index 6d955fe9b..c7a632105 100644 --- a/backends/cxxrtl/cxxrtl.h +++ b/backends/cxxrtl/cxxrtl.h @@ -904,10 +904,12 @@ std::ostream &operator<<(std::ostream &os, const value_formatted &vf) val = val.neg(); if (val.is_zero()) buf += '0'; - // TODO: rigorously check our signed behaviour here while (!val.is_zero()) { value quotient; - val.signedDivideWithRemainder(value{10u}, quotient); + if (negative) + val.signedDivideWithRemainder(value{10u}, quotient); + else + val.divideWithRemainder(value{10u}, quotient); buf += '0' + val.template slice<3, 0>().val().template get(); val = quotient; }