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

Make heap large chunk bit twiddling branchless #4526

Merged

Conversation

dipinhora
Copy link
Contributor

We use some bit twiddling operations for setting some flags on large chunks in actor heaps. Before this commit, the functionality was implemented with a ternary operator which would result in a branch.

This commit changes the logic to use bit shifts instead to avoid the branching.

We use some bit twiddling operations for setting some flags on large
chunks in actor heaps. Before this commit, the functionality was
implemented with a ternary operator which would result in a branch.

This commit changes the logic to use bit shifts instead to avoid
the branching.
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Oct 9, 2024
src/libponyrt/mem/heap.c Outdated Show resolved Hide resolved
Copy link
Member

@jemc jemc left a comment

Choose a reason for hiding this comment

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

This is good, but can you please move the three shift amounts (2, 3, 4, respectively) into #define preprocessor macros instead of inline integer literals here?

And then can you also refactor the definition of the three _BITMASK macros to rely on those shift amount macros?

That should make this change more robust to other changes across time.

@dipinhora
Copy link
Contributor Author

macro-ified

@jemc jemc merged commit 411e798 into ponylang:main Oct 15, 2024
21 checks passed
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label Oct 15, 2024
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.

3 participants