Skip to content

Generate 32-bit hashes on 32-bit platforms #14

Open

Description

@Amanieu

On 32-bit platforms HashMap only looks at the lowest 32 bits of the hash value. AHash could take advantage of this and only use 32-bit multiplications instead of 64-bit multiplications on such platforms.

Activity

  1. tkaitchuck commented on Aug 10, 2019

    @tkaitchuck
    Owner

    It's kindof odd to have a mode where the upper half of the bits of the hash are all zeros. Given that it is not something that is guaranteed in the documentation of the classes, perhaps a way to do it would be to have 2 32bit hashes in the output. It would allow for 32bit multiplication and only sacrifice the quality in as much as they don't relate to one another. Then if it really isn't being used by the hashmap the compiler can simply optimize one of them out. This is safer in the sense that if some code path actually uses those bits, they aren't just zeros.

  2. Amanieu commented on Aug 12, 2019

    @Amanieu
    ContributorAuthor

    On 32-bit platforms a 64-bit value is split into 2 registers anyways, so you could calculate 2 32-bit hashes separately and then combine them in the last step. The compiler can then eliminate one of the calculations if only the low 32 bits of the hash are used.

  3. Amanieu commented on Aug 12, 2019

    @Amanieu
    ContributorAuthor

    Maybe use the same hash algorithm as before but with a different seed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions