Created
January 23, 2017 11:24
-
-
Save NicolasT/1e9ebf807a32a27ac2be0d2b0a7ebb75 to your computer and use it in GitHub Desktop.
Slicing XOR hashing
This file contains hidden or 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 <stdint.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| #include <x86intrin.h> | |
| #include <avx2intrin.h> | |
| #ifdef __cplusplus | |
| extern "C" { | |
| void slice_xor(const unsigned char *data, size_t len, uint64_t *p1, uint64_t *p2); | |
| } | |
| #endif | |
| void slice_xor(const unsigned char *data, size_t len, uint64_t *p1, uint64_t *p2) { | |
| __m256i res = { 0 }; | |
| while(len >= 32) { | |
| __m256i current = _mm256_stream_load_si256((const __m256i *)data); | |
| res = _mm256_xor_si256(res, current); | |
| data += 32; | |
| len -= 32; | |
| } | |
| if(len > 0) { | |
| __m256i tmp = { 0 }; | |
| memcpy(&tmp, data, len); | |
| res = _mm256_xor_si256(res, tmp); | |
| } | |
| __m128i a = _mm256_extracti128_si256(res, 0), | |
| b = _mm256_extracti128_si256(res, 1); | |
| union { __m128i v; uint64_t i64[2]; } res2 = { .v = _mm_xor_si128(a, b) }; | |
| *p1 = res2.i64[0]; | |
| *p2 = res2.i64[1]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment