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

Introduce fast and deterministic RNG #615

Merged
merged 1 commit into from
Oct 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions tests/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,27 @@ static inline double bankersRounding(double val)
return ret;
}

static float ranf(void)
// SplitMix64 PRNG by Sebastiano Vigna, see:
// <https://xoshiro.di.unimi.it/splitmix64.c>
static uint64_t state; // the state of SplitMix64 PRNG
const double TWOPOWER64 = pow(2, 64);

#define SSE2NEON_INIT_RNG(seed) \
do { \
state = seed; \
} while (0)

static double next()
Cuda-Chen marked this conversation as resolved.
Show resolved Hide resolved
{
uint64_t z = (state += 0x9e3779b97f4a7c15);
z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9;
z = (z ^ (z >> 27)) * 0x94d049bb133111eb;
return z ^ (z >> 31);
}

static float ranf()
{
uint32_t ir = rand() & 0x7FFF;
return (float) ir * (1.0f / 32768.0f);
return next() / TWOPOWER64;
}

static float ranf(float low, float high)
Expand Down Expand Up @@ -11796,7 +11813,7 @@ SSE2NEONTestImpl::SSE2NEONTestImpl(void)
mTestFloatPointer2 = (float *) platformAlignedAlloc(sizeof(__m128));
mTestIntPointer1 = (int32_t *) platformAlignedAlloc(sizeof(__m128i));
mTestIntPointer2 = (int32_t *) platformAlignedAlloc(sizeof(__m128i));
srand(0);
SSE2NEON_INIT_RNG(123456);
for (uint32_t i = 0; i < MAX_TEST_VALUE; i++) {
mTestFloats[i] = ranf(-100000, 100000);
mTestInts[i] = (int32_t) ranf(-100000, 100000);
Expand Down
Loading