Created
October 6, 2015 06:02
-
-
Save tomilov/1fb709ff7c36a8435948 to your computer and use it in GitHub Desktop.
crc32 hash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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