Skip to content

Instantly share code, notes, and snippets.

@tomilov
Created October 6, 2015 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomilov/1fb709ff7c36a8435948 to your computer and use it in GitHub Desktop.
Save tomilov/1fb709ff7c36a8435948 to your computer and use it in GitHub Desktop.
crc32 hash
#include <iostream>
#include <cstdlib>
#include <cstddef>
#include <cstdint>
#include <x86intrin.h>
struct phash
{
std::size_t
operator () (void * _offset) const noexcept
{
#if defined(__x86_64__)
return _mm_crc32_u64(0, reinterpret_cast< std::uintptr_t >(_offset));
#elif defined(__i386__)
return _mm_crc32_u32(0, reinterpret_cast< std::uintptr_t >(_offset));
#endif
}
};
int
main()
{
using A = struct {};
A a[2];
std::cout << phash{}(a + 0) << '\t' << a + 0 << std::endl;
std::cout << phash{}(a + 1) << '\t' << a + 1 << std::endl;
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment