-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
include: zephyr: sys: Introduce IS_BIT_SET() macro #83683
include: zephyr: sys: Introduce IS_BIT_SET() macro #83683
Conversation
This macro is defined in a few places which leads to macro redefinition error e.g. when compiling prometheus network sample for NPCX boards. Provide one definition of IS_BIT_SET() in util_macro.h to fix the problem. Signed-off-by: Patryk Duda <[email protected]>
Replace DAI_INTEL_SSP_IS_BIT_SET() macro with IS_BIT_SET() macro from utils_macro.h. Signed-off-by: Patryk Duda <[email protected]>
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.
Seems like reasonable cleanup as far as it goes, but there are a LOT of places in the tree testing bits that never thought to use a standard API, these just happened to collide on a name. I guess my sense is that this doesn't really belong in util_macro.h, but if we're going to have it it makes sense to use it.
Also one tiny style nitpick.
* @param value Value that contain checked bit | ||
* @param bit Bit number | ||
*/ | ||
#define IS_BIT_SET(value, bit) ((((value) >> (bit)) & (0x1)) != 0) |
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.
Expressing this as a right shift seems needlessly confusing? ((BIT(bit) & (value)) != 0)
is shorter and has fewer parens, FWIW.
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.
On systems with 32 bit unsigned long
the ((BIT(bit) & (value)) != 0)
will not work properly for higher 32 bits of 64 bit value, due to shifting 1UL
for more bits than it has. Current approach doesn't have such issue.
This PR provides one definition of IS_BIT_SET() in util_macro.h and removes all other definitions.
This macro is defined in a few places which leads to macro redefinition error e.g. when compiling prometheus network sample for NPCX boards, see #81548.