Fix hash_instantiated_test and hash_test on big-endian - #2120
Closed
miladfarca wants to merge 2 commits into
Closed
Conversation
Contributor
Author
|
/cc @derekmauro |
derekmauro
requested changes
Jul 20, 2026
| for (size_t j = 0; j < 64; ++j) { | ||
| word |= static_cast<uint64_t>(vector[i + j]) << j; | ||
| } | ||
| word = absl::little_endian::FromHost64(word); |
Member
There was a problem hiding this comment.
Thanks for the fix. The new preferred way to do this is something like:
if constexpr (absl::endian::native == absl::endian::big) {
word = absl::byteswap(word);
}
Contributor
Author
There was a problem hiding this comment.
Thank you for reviewing, I've updated it to use the new method.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The two tests are failing on big-endian platforms after 63c77e4.
The new bit-packing code stores packed bits in the LSB of a uint64_t, then feeds raw bytes via reinterpret_cast. On big-endian, the LSB is at the end of the memory layout, so the partial-word path reads leading zero bytes instead of the actual data, causing hash collisions between distinct inputs.
Fix by byte-swapping the word to little-endian layout before feeding it to the combiner.