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
sys/bitfield: add support for bit-wise bitfield operations #17710
Conversation
b47fb4f
to
5785556
Compare
5785556
to
5c0cb8b
Compare
* @param[in] a The first bitfield | ||
* @param[in] b The second bitfield | ||
* @param[in] len The size of the bitfield in bytes | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add a @pre
stating that the size for a, b, and c must be greater than len
.
Also, I would rephrase to something like
* @param[in] len The number of bytes to which the operation is applied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the size for a, b, and c must be greater than
len
.
Shouldn't it be at least len
?
I assumed one would typically run the operation on the whole bitfield, not arbitrary byte-sized chunks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, it should just be documented exactly to make sure that it is the responsibility of the caller to check these preconditions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this is stating the obvious, but there you go
5c0cb8b
to
c55cd51
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exiting functions/macros use size
as the number of bits.
There already is an operation int bf_get_unset(uint8_t field[], int size);
which has a size parameter, they should all use the same type - seems size_t
would be correct.
bitfield.h
also seems to miss some kind of initialization illustrated by the example l202 and l203
I agree on this. Also, using bits vs. bytes doesn't fail as horrible as if someone supplies the number of bits as bytes argument. (does this sentence make sense?) |
I'd like to see a line or two on the unused bits of a bitfield and how they are affected by the ops. I mean, a "bitfield" of 10 bits uses 2 bytes of storage. the unused 6 bits will get modified by the current and/or/xor implementations. That is fine IMO, but should be documented. |
8ab7441
to
2a616ab
Compare
7d804e4
to
acbeb52
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
murdock test are sufficient in this case, and murdock is green.
Contribution description
This adds support for bit-wise (AND, OR, XOR, NOT) operations to bitfields.
Testing procedure
The
tests-bitfield
unit test has been extended with the new operations.Issues/PRs references