Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LFSR/PRNG Asynchronous Safety, Use Vec[Bool] to store internal state #1092

Merged
merged 1 commit into from
May 10, 2019

Conversation

seldridge
Copy link
Member

@seldridge seldridge commented May 9, 2019

Changes the internal state of PRNG to use Vec[Bool] instead of UInt.
This fixes an @aswaterman identified future problem with asynchronous
reset.

A register with an asynchronous reset can only be reset to a literal.
Previously, an LFSR would store state as a UInt. If it was not
parameterized with a seed it should have its least significant bit
reset to something to avoid locking up. It's ideal to not reset the
full UInt (better test coverage, decreased reset fanout). However,
it's difficult to only reset one bit of a UInt. Conversely, it's
trivial to reset one bit of a Vec[Bool]. This also moves PRNG/LFSR
closer to a canonical representation of their internal state, i.e.,
it's natural to think of generalizing Vec[Bool] to arbitrary finite
fields (Vec[A <: Field]) whereas UInt is tightly coupled to GF2.

The specific change for async reset can be seen here:

Minor updates:

  • Updates/fixes to some scaladoc
  • Add assertion to period test to make sure LFSR is changing

Signed-off-by: Schuyler Eldridge schuyler.eldridge@ibm.com

Related issue:

Type of change: other enhancement

Impact: API modification

Development Phase: implementation

Release Notes

  • Use Vec[Bool] for internal LFSR/PRNG state

@seldridge seldridge requested a review from a team as a code owner May 9, 2019 21:11
Copy link
Contributor

@chick chick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. The Vec[Bool] makes the code look cleaner I think.
Probably should get another Approve from some of the others who have weighed in here

@seldridge
Copy link
Member Author

Thanks for taking a look @chickm. I'll wait for somebody else to jump in before merging. Yeah, I think UInt was wrong... things are easier and more natural to express with Vec[Bool]. The generated FIRRTL/Verilog is more structural with Vec[Bool], but is subjectively easier to read, too.

@aswaterman
Copy link
Member

Depending on the implementation of the async reset stuff, the when (reset.toBool) construct won't be valid. If not, we'll have to make state a Seq[Bool] where the first element is a RegInit and the subsequent ones are Regs. But I think we can cross that bridge when we get there, since state is now private.

Changes the internal state of PRNG to use Vec[Bool] instead of UInt.
This fixes an @aswaterman identified future problem with asynchronous
reset.

A register with an asynchronous reset can only be reset to a literal.
Previously, an LFSR would store state as a UInt. If it was not
parameterized with a seed it should have its least significant bit
reset to something to avoid locking up. It's ideal to not reset the
full UInt (better test coverage, decreased reset fanout). However,
it's difficult to only reset one bit of a UInt. Conversely, it's
trivial to reset one bit of a Vec[Bool]. This also moves PRNG/LFSR
closer to a canonical representation of their internal state, i.e.,
it's natural to think of generalizing Vec[Bool] to arbitrary finite
fields (Vec[A <: Field]) whereas UInt is tightly coupled to GF2.

Minor updates:

- Updates/fixes to some scaladoc
- Add assertion to period test to make sure LFSR is changing

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
@seldridge
Copy link
Member Author

I'll wait for this to rebase and merge it, then. Thanks for the explanation @aswaterman.

@seldridge seldridge merged commit e02d25c into master May 10, 2019
@seldridge seldridge deleted the lfsr-async-reset branch May 10, 2019 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants