Repository navigation
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
bfxw() built its mask with bitmask((lsb + width, lsb)), but bitmask() ranges include both ends, so the mask covered width + 1 bits. For example, bfxw(0x1f0, 4, 4) returned 0x1f instead of 0xf. Use lsb + width - 1 as the MSB so the result matches bfx(). A width of 0 now selects no bits and returns 0. Add unit tests comparing bfxw() against bfx().
LukeW1999
force-pushed
the
fix-bfxw-width
branch
from
November 28, 2026 11:31
9a0cee3 to
37f66b0
Compare
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.
bfxw(value, lsb, width)built its mask withbitmask((lsb + width, lsb)).bitmask()ranges include both ends, so the mask coveredwidth + 1bits. For example,bfxw(0x1f0, 4, 4)returned0x1finstead of0xf.This was found by bounded model checking with ESBMC, checking
bfxw(v, lsb, w) < 1 << w. Counterexample:v=4294955007 (0xffffcfff), lsb=12, w=2returns 4. It was confirmed by running the code directly.The fix uses
lsb + width - 1as the MSB, sobfxw()now agrees withbfx(). A width of 0 selects no bits and returns 0. Nothing in the tree callsbfxw(), so no existing behaviour changes.Added
test/unit/test_mask.py, which comparesbfxw()againstbfx()for a table of inputs (including width 1, the example above and the counterexample) and checks the result is below1 << width. Unit tests: 1116 passed, 41 skipped.