-
Notifications
You must be signed in to change notification settings - Fork 49
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
Decouple interrupt bit index calculation from ilog2 #44
Conversation
ilog2 is a common function, but interrupt bit index calculation is application dependent. Thus, decouple them and create a new macro called GET_INTR_IDX which leverages the ilog2 to calculate the interrupt bit index.
@@ -14,9 +14,20 @@ | |||
/* Ensure that __builtin_clz is never called with 0 argument */ | |||
static inline int ilog2(int x) | |||
{ | |||
return 31 - __builtin_clz(x | 1); | |||
return __builtin_clz(x | 1); |
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.
floor(log2(x)) should be 31 - __builtin_clz(x | 1)
.
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.
floor(log2(x)) should be
31 - __builtin_clz(x | 1)
.
31 - __builtin_clz(x | 1)
seems like a calculation of first bit set index in a 32-bit number instead of floor(log2(x)) ?
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.
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.
Check this: https://github.com/apple/swift-llbuild/blob/main/include/llvm/Support/MathExtras.h#L536-L541
Seems like I had misunderstood it. I will close this PR.
* GET_INTR_IDX(4) = 2 | ||
* GET_INTR_IDX(8) = 3 | ||
*/ | ||
#define GET_INTR_IDX(x) (31 - ilog2(x)) |
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 naming is confusing. Refine it.
ilog2 is a common function, but interrupt bit index calculation is application dependent. Thus, decouple them and create a new macro called GET_INTR_IDX which leverages the ilog2 to calculate the interrupt bit index.