Skip to content

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

Open
@nstilt1

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions