← Back to Pull requests

Resolve implicit-width-truncation warnings #3822

Open
tynan-jdwk opened this pull request with 362 lines diff across 34 files
View on GitHub
tynan-jdwk tynan-jdwk commented on Aug 15, 2026 23:11 UTC
Author

firtool-1.154.0 and later warn on all implicit width truncations (https://github.com/llvm/circt/pull/10621). These width truncations were flagged in stock Chipyard builds.

The commits in this PR are separated by the type of truncation fix, and the commit messages describe why the fix was made, and why the resulting RTL is equivalent to the existing design.

<!--
Please select the item best describing the pull request in each category and delete the other items.
-->
Related issue: N/A

<!-- choose one -->
Type of change: other enhancement

<!-- choose one -->
Impact: no functional change

<!-- choose one -->
Development Phase: implementation

Release Notes
<!--
Text from here to the end of the body will be considered for inclusion in the release notes for the version containing this pull request.
-->

Resolve implicit-width-truncation warnings

Diff: 362 lines (+194 / -168) across 34 files Reviewer: jackkoenig Review duration: 96445m
All Vouch review confidence checks passed
Residual risk 0.11 = Change Risk (0.74) × (1 − Review Confidence (0.85)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.74 · 362 lines diff across 34 files
0.74
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.90 · 5 substantive comment(s)
0.90
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
85%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.353
Mass File Touch mass_file_touch
0.080
Real PR Conversation Timeline
7 items
jackkoenig jackkoenig commented on code on Aug 15, 2026 23:40 UTC
Code Review
src/main/scala/devices/debug/Debug.scala:1
@@ -1323,18 +1323,18 @@ class TLDebugModuleInner(device: Device, getNComponents: () => Int, beatBytes: I
         val hartselIndex        = UIntToOH(io.innerCtrl.bits.hartsel)
         when (hartHaltedWrEn) {
           // add those harts halting and remove those in reset
-          haltedBitRegs := (haltedBitRegs | hartHaltedIdIndex) & ~(hartIsInResetSync.asUInt)
+          haltedBitRegs :<= ((haltedBitRegs | hartHaltedIdIndex) & ~(hartIsInResetSync.asUInt)).squeeze
         }.elsewhen (hartResumingWrEn) {
           // remove those harts in reset and those in resume
-          haltedBitRegs := (haltedBitRegs & ~(hartResumingIdIndex)) & ~(hartIsInResetSync.asUInt)
+          haltedBitRegs :<= ((haltedBitRegs & ~(hartResumingIdIndex)) & ~(hartIsInResetSync.asUInt)).squeeze

          haltedBitRegs :%= ((haltedBitRegs & ~(hartResumingIdIndex)) & ~(hartIsInResetSync.asUInt))

I personally would use the new truncating connection operator[[1]](https://www.chisel-lang.org/docs/explanations/connectable#connecting-components-with-different-widths) (only defined on Bits) because with complex expressions on the RHS it can be easy to miss the .squeeze at the end.

jackkoenig jackkoenig commented on code on Aug 15, 2026 23:47 UTC
Code Review
src/main/scala/devices/debug/Custom.scala:1
@@ -84,7 +84,7 @@ class DebugCustomXbar(
     }
     // mux correct 'ready' and 'data' based on address
     sink.ready := (decoded zip sources).foldLeft(false.B){case (result, (d, i)) => result || (d & i.ready)}
-    sink.data := (decoded zip sources).foldLeft(0.U){ case (result, (d, i)) => result | Mux(i.ready, i.data, 0.U)}
+    sink.data :<= (decoded zip sources).foldLeft(0.U(sink.data.getWidth.W)){ case (result, (d, i)) => result | Mux(i.ready, i.data, 0.U)}

    sink.data :<= (decoded zip sources).foldLeft(0.U(0.W)){ case (result, (d, i)) => result | Mux(i.ready, i.data, 0.U(0.W)}

I'm assuming this only fixes things when sink.data is 0-width (because 0.U is 1-bit[^1]) so you can probably just do this?

[^1]: I want to change it to 0-bit but until implicit truncation is gone that could silently change behavior

jackkoenig jackkoenig commented on code on Aug 15, 2026 23:49 UTC
Code Review
src/main/scala/devices/debug/Debug.scala:1
@@ -1323,18 +1323,18 @@ class TLDebugModuleInner(device: Device, getNComponents: () => Int, beatBytes: I
         val hartselIndex        = UIntToOH(io.innerCtrl.bits.hartsel)
         when (hartHaltedWrEn) {
           // add those harts halting and remove those in reset
-          haltedBitRegs := (haltedBitRegs | hartHaltedIdIndex) & ~(hartIsInResetSync.asUInt)
+          haltedBitRegs :<= ((haltedBitRegs | hartHaltedIdIndex) & ~(hartIsInResetSync.asUInt)).squeeze
         }.elsewhen (hartResumingWrEn) {
           // remove those harts in reset and those in resume
-          haltedBitRegs := (haltedBitRegs & ~(hartResumingIdIndex)) & ~(hartIsInResetSync.asUInt)
+          haltedBitRegs :<= ((haltedBitRegs & ~(hartResumingIdIndex)) & ~(hartIsInResetSync.asUInt)).squeeze

If the issue is using older Chisel, that's fine because you can easily copy the implementation of :%= in to rocket-chip, it uses extension methods anyway

tynan-jdwk tynan-jdwk commented on code on Aug 16, 2026 02:38 UTC
Code Review
src/main/scala/devices/debug/Debug.scala:1
@@ -1323,18 +1323,18 @@ class TLDebugModuleInner(device: Device, getNComponents: () => Int, beatBytes: I
         val hartselIndex        = UIntToOH(io.innerCtrl.bits.hartsel)
         when (hartHaltedWrEn) {
           // add those harts halting and remove those in reset
-          haltedBitRegs := (haltedBitRegs | hartHaltedIdIndex) & ~(hartIsInResetSync.asUInt)
+          haltedBitRegs :<= ((haltedBitRegs | hartHaltedIdIndex) & ~(hartIsInResetSync.asUInt)).squeeze
         }.elsewhen (hartResumingWrEn) {
           // remove those harts in reset and those in resume
-          haltedBitRegs := (haltedBitRegs & ~(hartResumingIdIndex)) & ~(hartIsInResetSync.asUInt)
+          haltedBitRegs :<= ((haltedBitRegs & ~(hartResumingIdIndex)) & ~(hartIsInResetSync.asUInt)).squeeze

Indeed the reason I didn't use :%= was to allow Rocket Chip to continue to work with older Chisel, but copying this implementation in sounds like a great idea.

tynan-jdwk tynan-jdwk commented on code on Aug 16, 2026 04:42 UTC
Code Review
src/main/scala/devices/debug/Custom.scala:1
@@ -84,7 +84,7 @@ class DebugCustomXbar(
     }
     // mux correct 'ready' and 'data' based on address
     sink.ready := (decoded zip sources).foldLeft(false.B){case (result, (d, i)) => result || (d & i.ready)}
-    sink.data := (decoded zip sources).foldLeft(0.U){ case (result, (d, i)) => result | Mux(i.ready, i.data, 0.U)}
+    sink.data :<= (decoded zip sources).foldLeft(0.U(sink.data.getWidth.W)){ case (result, (d, i)) => result | Mux(i.ready, i.data, 0.U)}

Ya, that does work, I'll go with this.

tynan-jdwk tynan-jdwk commented on code on Aug 16, 2026 05:42 UTC
Code Review
src/main/scala/devices/debug/Debug.scala:1
@@ -1323,18 +1323,18 @@ class TLDebugModuleInner(device: Device, getNComponents: () => Int, beatBytes: I
         val hartselIndex        = UIntToOH(io.innerCtrl.bits.hartsel)
         when (hartHaltedWrEn) {
           // add those harts halting and remove those in reset
-          haltedBitRegs := (haltedBitRegs | hartHaltedIdIndex) & ~(hartIsInResetSync.asUInt)
+          haltedBitRegs :<= ((haltedBitRegs | hartHaltedIdIndex) & ~(hartIsInResetSync.asUInt)).squeeze
         }.elsewhen (hartResumingWrEn) {
           // remove those harts in reset and those in resume
-          haltedBitRegs := (haltedBitRegs & ~(hartResumingIdIndex)) & ~(hartIsInResetSync.asUInt)
+          haltedBitRegs :<= ((haltedBitRegs & ~(hartResumingIdIndex)) & ~(hartIsInResetSync.asUInt)).squeeze

Just did this, thanks for the suggestion!

Reviewers
Assignees
tynan-jdwk tynan-jdwk
Labels
risk: low confidence: 85.4% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 73.8% (HIGH) · Higher = larger blast radius
73.8%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 85.4% · Lower = rushed or shallow review
85.4%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 10.8% · Safe to merge
10.8%