Change BitfieldExtract to use a pointer to the bitfield member #9633
+164
−79
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.
This PR changes
BitfieldExtractto use a pointer to a member to deduce information about the BitField instead of creating a temporary variable and passing its bitfield instance. The pointer-to-member is also a template argument instead of a regular argument. For example,BitfieldExtract("colorreg", LitChannel().matsource)is nowBitfieldExtract<&LitChannel::matsource>("colorreg"), andBitfieldExtract("ss.cc", TevStageCombiner().colorC.bias)is nowBitfieldExtract<&TevStageCombiner::ColorCombiner::bias>("ss.cc").As an additional change to make this work, I made
BitField::StartBitandBitField::NumBitsstatic. The other code that already usedStartBitis not affected by this change (for instanceint(TwoTevStageOrders().enable1.StartBit() - TwoTevStageOrders().enable0.StartBit())).Note that this does not make any difference with performance (compiler explorer); the only change is the syntax.
This didn't take too long to do, and it's subjective whether or not this is really an improvement. If people don't like it, then I'm fine with it not being merged.