Repository navigation
Expose nextCount on Counter - #307
Open
Shubham-Padkonde wants to merge 1 commit into
Open
Shubham-Padkonde wants to merge 1 commit into
Shubham-Padkonde wants to merge 1 commit into
Conversation
Counter already computes the upcoming value: `summer.sum` is exactly what gets flopped into `count`. Surface it as a `nextCount` output so callers that need to know the count a cycle early can use it without instantiating a second Sum. GatedCounter overrides buildFlops to flop the same `summer.sum` through gated clocks, so it inherits the output; a randomized test covers both to confirm the gating does not make the prediction lie. Fixes intel#264 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Counteralready computes the upcoming value.summer.sumis exactly whatbuildFlopsregisters intocount:This exposes it as a
nextCountoutput, so a caller that needs the count a cycle early can read it instead of instantiating a secondSum— which is the "reuse the sameSumhardware" the issue asks for. It is driven in_buildLogicfrom the samesummer, so there is no new arithmetic.GatedCounteroverridesbuildFlopsto register that samesummer.sumthrough gated clocks, so it inherits the output. That raised the obvious question — whether a gated-off clock makes the prediction wrong, since the flop holds whilesummer.summay have moved — so the test below coversGatedCounterexplicitly rather than assuming. It does not: the gate enables exactly when the value needs to change.Related Issue(s)
Fixes #264
Testing
New
test/summation/counter_next_count_test.dart. Rather than asserting specific numbers, it checks the property that actually matters — thenextCountvisible this cycle is thecountvisible the next one — over 50 cycles of a randomized enable pattern:It runs against both
Counter.simple(...)and aGatedCounter, including cycles where the counter is disabled and the value must stay put.Full suite,
dart test -j 3, cleanmainversus this branch:No failures either way; the +2 is the new tests.
dart format --output=none --set-exit-if-changedreports no changes, anddart analyzeover the package finds no issues.Backwards-compatibility
Additive: a new output port on
Counterand a new getter. Nothing existing changes behaviour.The one visible consequence is that
Counter(andGatedCounter) now have an extra port in generated SystemVerilog. If you would rather this be opt-in behind a constructor flag so unused instances don't carry the port, say so and I'll rework it that way — I went with always-present because it costs no logic beyond the wire, and an unused output is normally optimized away downstream.Documentation
The
nextCountgetter carries a doc comment explaining what it is and that it shares the existingSum.doc/components/summation.mddocuments the summation components at a level that doesn't enumerate individual ports, so nothing there needed updating — happy to add a line if you'd like it mentioned.Disclosure: this change was written by Claude Code (Claude Opus 5) working as my agent, at my direction. The test output quoted above comes from real runs in my local environment; I am accountable for the content of this PR and happy to iterate on review feedback.
🤖 Generated with Claude Code