Created
September 14, 2020 08:37
-
-
Save chiro-hiro/0ffeb0b2b00d25d08b1aef48e2993a31 to your computer and use it in GitHub Desktop.
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 <immintrin.h> | |
// Global seed value | |
__m256i seed; | |
// Use SSE2 perform pesudo random for given seed | |
__m128i xor_shift_plus_pro() | |
{ | |
// t = 0 | |
__m128i t = _mm_setzero_si128(); | |
// s = 0 | |
__m128i s = _mm_setzero_si128(); | |
// t = seed >> 128 | |
// s = seed & 0xffffffffffffffff | |
_mm256_storeu2_m128i(&t, &s, seed); | |
// t ^= t << 23; | |
t = _mm_xor_si128(t, _mm_bslli_si128(t, 23)); | |
// t ^= t >> 17; | |
t = _mm_xor_si128(t, _mm_bsrli_si128(t, 17)); | |
// t ^= s ^ (t >> 26) | |
t = _mm_xor_si128(t, _mm_xor_si128(s, _mm_bsrli_si128(t, 26))); | |
// seed = (s << 128) | t | |
seed = _mm256_set_m128i(s, t); | |
return _mm_add_epi32(s, t); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment