From 31d6768f806deaf5071ef60dd08b697db342a402 Mon Sep 17 00:00:00 2001 From: unlsycn Date: Sun, 24 Nov 2024 18:07:55 +0800 Subject: [PATCH] fix: fix while loop in ReverseImpl (#4525) Reference: https://docs.scala-lang.org/scala3/reference/dropped-features/do-while.html#why-drop-the-construct-1 Signed-off-by: unlsycn --- src/main/scala/chisel3/util/BitwiseImpl.scala | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/scala/chisel3/util/BitwiseImpl.scala b/src/main/scala/chisel3/util/BitwiseImpl.scala index 3c359ba42d..3d9edea541 100644 --- a/src/main/scala/chisel3/util/BitwiseImpl.scala +++ b/src/main/scala/chisel3/util/BitwiseImpl.scala @@ -56,13 +56,12 @@ private[chisel3] trait ReverseImpl { var res = in var shift = length >> 1 var mask = ((BigInt(1) << length) - 1).asUInt(length.W) - var initial = true - while (initial || shift > 0) { - initial = false + while ({ mask = mask ^ (mask(length - shift - 1, 0) << shift) - res = ((res >> shift) & mask) | ((res(length - shift - 1, 0) << shift) & !mask) + res = ((res >> shift) & mask) | ((res(length - shift - 1, 0) << shift) & ~mask) shift = shift >> 1 - } + shift > 0 + }) {} res case _ => val half = (1 << log2Ceil(length)) / 2