[PATCH] D41993: [ELF] - Change shift2 constant of GNU_HASH from 6->11.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 24 10:11:12 PST 2018


George Rimar <grimar at accesssoftek.com> writes:

> +unsigned GnuHashTableSection::findShift2Score(size_t Shift) const {
> +  unsigned C = Config->Is64 ? 64 : 32;
> +  std::vector<uint64_t> Bloom(MaskWords);
> +  unsigned Score = 0;
> +  for (const Entry &Sym : Symbols) {
> +    uint64_t &Value = Bloom[(Sym.Hash / C) & (MaskWords - 1)];
> +
> +    uint64_t Bit1 = uint64_t(1) << (Sym.Hash % C);
> +    if ((Value & Bit1) == 1)
> +      ++Score;
> +    Value |= uint64_t(1) << (Sym.Hash % C);
> +
> +    uint64_t Bit2 = uint64_t(1) << ((Sym.Hash >> Shift) % C);
> +    if ((Value & Bit2) == 1)
> +      ++Score;
> +    Value |= Bit2;
> +  }
> +  return Score;
> +}

This is not what I meant by most 0 or must 1. Instead of adding to Score
every time there is a collision, what I had in mind was to just count
the number of 1 bits in the Bloom std::vector:

unsigned GnuHashTableSection::findShift2Score(size_t Shift) const {
  unsigned C = Config->Is64 ? 64 : 32;
  std::vector<uint64_t> Bloom(MaskWords);
  for (const Entry &Sym : Symbols) {
    uint64_t &Value = Bloom[(Sym.Hash / C) & (MaskWords - 1)];

    uint64_t Bit1 = uint64_t(1) << (Sym.Hash % C);
    Value |= uint64_t(1) << (Sym.Hash % C);

    uint64_t Bit2 = uint64_t(1) << ((Sym.Hash >> Shift) % C);
    Value |= Bit2;
  }
  unsigned Score = 0;
  for (uint64_t V : Bloom)
    Score += numberOfSetBits(V);
  return Score;
}


> +size_t GnuHashTableSection::optimizeShift2() {
> +  if (!Config->Is64)
> +    return 5;
> +
> +  unsigned BestScore = 0;
> +  size_t BestId = 0;
> +
> +  for (size_t I = 0; I < 32; ++I) {

0 is a special case that we should probably ignore.

Cheers,
Rafael


More information about the llvm-commits mailing list