Skip to content

Commit 2090d66

Browse files
committed
[lld-macho] Switch to xxh3_64bits
xxh3 is substantially faster than xxh64. For lld/ELF, there is substantial speedup in `.debug_str` duplicate elimination (D154813). Use xxh3 for lld-macho as well. Reviewed By: #lld-macho, oontvoo Differential Revision: https://reviews.llvm.org/D155677
1 parent 0ea1183 commit 2090d66

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

lld/MachO/ICF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ void macho::foldIdenticalSections(bool onlyCfStrings) {
457457
assert(isec->icfEqClass[0] == 0); // don't overwrite a unique ID!
458458
// Turn-on the top bit to guarantee that valid hashes have no collisions
459459
// with the small-integer unique IDs for ICF-ineligible sections
460-
isec->icfEqClass[0] = xxHash64(isec->data) | (1ull << 31);
460+
isec->icfEqClass[0] = xxh3_64bits(isec->data) | (1ull << 31);
461461
});
462462
// Now that every input section is either hashed or marked as unique, run the
463463
// segregation algorithm to detect foldable subsections.

lld/MachO/InputSection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ void CStringInputSection::splitIntoPieces() {
246246
size_t end = s.find(0);
247247
if (end == StringRef::npos)
248248
fatal(getLocation(off) + ": string is not null terminated");
249-
uint32_t hash = deduplicateLiterals ? xxHash64(s.take_front(end)) : 0;
249+
uint32_t hash = deduplicateLiterals ? xxh3_64bits(s.take_front(end)) : 0;
250250
pieces.emplace_back(off, hash);
251251
size_t size = end + 1; // include null terminator
252252
s = s.substr(size);

lld/MachO/SyntheticSections.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,7 @@ void DeduplicatedCStringSection::writeTo(uint8_t *buf) const {
16771677
DeduplicatedCStringSection::StringOffset
16781678
DeduplicatedCStringSection::getStringOffset(StringRef str) const {
16791679
// StringPiece uses 31 bits to store the hashes, so we replicate that
1680-
uint32_t hash = xxHash64(str) & 0x7fffffff;
1680+
uint32_t hash = xxh3_64bits(str) & 0x7fffffff;
16811681
auto offset = stringOffsetMap.find(CachedHashStringRef(str, hash));
16821682
assert(offset != stringOffsetMap.end() &&
16831683
"Looked-up strings should always exist in section");

lld/MachO/Writer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,14 +1190,14 @@ void Writer::writeUuid() {
11901190
threadFutures.reserve(chunks.size());
11911191
for (size_t i = 0; i < chunks.size(); ++i)
11921192
threadFutures.emplace_back(threadPool.async(
1193-
[&](size_t j) { hashes[j] = xxHash64(chunks[j]); }, i));
1193+
[&](size_t j) { hashes[j] = xxh3_64bits(chunks[j]); }, i));
11941194
for (std::shared_future<void> &future : threadFutures)
11951195
future.wait();
11961196
// Append the output filename so that identical binaries with different names
11971197
// don't get the same UUID.
1198-
hashes[chunks.size()] = xxHash64(sys::path::filename(config->finalOutput));
1199-
uint64_t digest = xxHash64({reinterpret_cast<uint8_t *>(hashes.data()),
1200-
hashes.size() * sizeof(uint64_t)});
1198+
hashes[chunks.size()] = xxh3_64bits(sys::path::filename(config->finalOutput));
1199+
uint64_t digest = xxh3_64bits({reinterpret_cast<uint8_t *>(hashes.data()),
1200+
hashes.size() * sizeof(uint64_t)});
12011201
uuidCommand->writeUuid(digest);
12021202
}
12031203

0 commit comments

Comments
 (0)