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

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

Open
Amanieu opened this issue Aug 3, 2019 · 3 comments
Open

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

Amanieu opened this issue Aug 3, 2019 · 3 comments

Comments

@Amanieu
Copy link
Contributor

Amanieu commented Aug 3, 2019

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.

@tkaitchuck
Copy link
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.

@Amanieu
Copy link
Contributor Author

Amanieu commented Aug 12, 2019

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.

@Amanieu
Copy link
Contributor Author

Amanieu commented Aug 12, 2019

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants