[PATCH] D55971: [ELF] .gnu.hash bloom filter: use Shift2 = 26 instead of 2

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 20 16:58:04 PST 2018


ruiu added a comment.

Discussed with Ambrose and I'm convinced that this change makes sense.

So, this is the code to create the bitmap.

  for (const Entry &Sym : Symbols) {
    size_t I = (Sym.Hash / C) & (MaskWords - 1);
    uint64_t Val = readUint(Buf + I * Config->Wordsize);
    // We choose Shift2 = 26 to give us high 6 bits for the 64-bit case,
    // (nearly) independent from the low 6 bits, and thus less collision.
    Val |= uint64_t(1) << (Sym.Hash % C);
    Val |= uint64_t(1) << ((Sym.Hash >> Shift2) % C);
    writeUint(Buf + I * Config->Wordsize, Val);
  }

Assume a 64-bit target, then C is 64 (or 1 << 6). We compute `I` which is bit [N:6] of Sym.Hash where N is some integer. (Sym.Hash % C) is bit [0:5]. ((Sym.Hash >> Shift2) % C) is bit [11:6]. Thus, `I` and the last expression are likely to compute the same value. That results in setting the same bit again and again for each word, so even though we have two bits for each word, we effectively has only one bit if that happens.


Repository:
  rLLD LLVM Linker

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55971/new/

https://reviews.llvm.org/D55971





More information about the llvm-commits mailing list