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

Avoid misaligned loads from StaticRandomData in the size [4, 8] hashing case. #4743

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion common/hashing.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,13 @@ class Hasher {
return data;
}

// As above, but for small offsets, we can use aligned loads, which are
// faster. The offset must be in the range [0, 8).
static auto SampleAlignedRandomData(ssize_t offset) -> uint64_t {
CARBON_DCHECK(offset < sizeof(StaticRandomData) / sizeof(uint64_t));
return StaticRandomData[offset];
}

// Random data taken from the hexadecimal digits of Pi's fractional component,
// written in lexical order for convenience of reading. The resulting
// byte-stream will be different due to little-endian integers. These can be
Expand Down Expand Up @@ -950,7 +957,7 @@ inline auto Hasher::HashSizedBytes(llvm::ArrayRef<std::byte> bytes) -> void {
// Note that we don't drop to the `WeakMix` routine here because we want
// to use sampled random data to encode the size, which may not be as
// effective without the full 128-bit folded result.
buffer = Mix(data ^ buffer, SampleRandomData(size));
buffer = Mix(data ^ buffer, SampleAlignedRandomData(size - 1));
CARBON_MCA_END("dynamic-8b");
return;
}
Expand Down
Loading