Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

ChinYikMing
Copy link
Collaborator

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.

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);
Copy link
Collaborator

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).

Copy link
Collaborator Author

@ChinYikMing ChinYikMing May 16, 2024

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)) ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

@ChinYikMing ChinYikMing May 16, 2024

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))
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants