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

chacha20: Developer QoL Improvement by Removing Unnecessary Bit Operations #382

Open
nstilt1 opened this issue Jan 1, 2025 · 0 comments

Comments

@nstilt1
Copy link
Contributor

nstilt1 commented Jan 1, 2025

When I originally wrote/copied the RNG implementation, I used a bunch of bit operations because I thought they were more efficient than multiplication, division, and modulo. They would be more efficient, however, I recently learned a little more about the compiler and discovered that when constants are involved in multiplication, division, and modulo operations, the compiler optimizes the operation with bit operations. Therefore, all bit operations do is make it slightly easier to compile rather than resulting in a small performance boost at runtime, at least when constants are involved like they originally were.

There are some instances where bit operations make some sense, such as when calculating the word position of the RNG, but using them everywhere only makes the code base a little harder to maintain. I am willing to remove all of the unnecessary bit operations to make the code a little more readable, using constants. I reckon this could be done with a single commit.

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

No branches or pull requests

1 participant