Force hashing to be done on aligned usizes #35
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This is a WIP/PoC of doing hashing on aligned usizes. This seems to reduce the size of the generated assembly, and I would like to benchmark it, but I don't know how to run a compiler bench using a modified crate.
Drawbacks of this PR:
Explanation
Let's call N the size in bytes of a usize.
Two cases are distinguished. First if
bytes.len() < N
, then the previous strategy is used, that is 32 bits are read, then 16, then 8.However, if the slice is at least N long, we can:
align_to
guarantees that this slice is maximalThese three elements may overlap, but they cover all input bytes. We can now add to the hasher all these usizes, and the compiler will take advantage of the middle slice being well aligned.
Remarks
I haven't updated the tests so it will inevitably fail CI.