diff --git a/docs/ispc.rst b/docs/ispc.rst index a5ada9d9..5d26c93a 100644 --- a/docs/ispc.rst +++ b/docs/ispc.rst @@ -3147,7 +3147,7 @@ library. State for the RNG is maintained in an instance of the :: struct RNGState; - void seed_rng(varying RNGState * uniform state, uniform int seed) + void seed_rng(varying RNGState * uniform state, int seed) void seed_rng(uniform RNGState * uniform state, uniform int seed) After the RNG is seeded, the ``random()`` function can be used to get a diff --git a/examples/aobench/ao.ispc b/examples/aobench/ao.ispc index 692dc367..e768c8c7 100644 --- a/examples/aobench/ao.ispc +++ b/examples/aobench/ao.ispc @@ -210,7 +210,7 @@ static void ao_scanlines(uniform int y0, uniform int y1, uniform int w, { { 1.0f, 0.0f, -2.2f }, 0.5f } }; RNGState rngstate; - seed_rng(&rngstate, y0); + seed_rng(&rngstate, programIndex + (y0 << (programIndex & 15))); float invSamples = 1.f / nsubsamples; foreach_tiled(y = y0 ... y1, x = 0 ... w, diff --git a/examples/aobench_instrumented/ao.ispc b/examples/aobench_instrumented/ao.ispc index 06d9b505..4fd9bedb 100644 --- a/examples/aobench_instrumented/ao.ispc +++ b/examples/aobench_instrumented/ao.ispc @@ -211,7 +211,7 @@ static void ao_scanlines(uniform int y0, uniform int y1, uniform int w, { { 1.0f, 0.0f, -2.2f }, 0.5f } }; RNGState rngstate; - seed_rng(&rngstate, y0); + seed_rng(&rngstate, programIndex + (y0 << (programIndex & 15))); // Compute the mapping between the 'programCount'-wide program // instances running in parallel and samples in the image. diff --git a/stdlib.ispc b/stdlib.ispc index 4cfcdea4..ea4c6b98 100644 --- a/stdlib.ispc +++ b/stdlib.ispc @@ -4026,60 +4026,13 @@ static inline uniform float frandom(uniform RNGState * uniform state) return floatbits(0x3F800000 | irand)-1.0f; } -static inline uniform unsigned int __seed4(varying RNGState * uniform state, - uniform int start, - uniform unsigned int seed) { - uniform unsigned int c1 = 0xf0f0f0f0; - uniform unsigned int c2 = 0x0f0f0f0f; - - state->z1 = insert(state->z1, start + 0, seed); - state->z1 = insert(state->z1, start + 1, seed ^ c1); - state->z1 = insert(state->z1, start + 2, (seed << 3) ^ c1); - state->z1 = insert(state->z1, start + 3, (seed << 2) ^ c2); - - seed += 131; - state->z2 = insert(state->z2, start + 0, seed); - state->z2 = insert(state->z2, start + 1, seed ^ c1); - state->z2 = insert(state->z2, start + 2, (seed << 3) ^ c1); - state->z2 = insert(state->z2, start + 3, (seed << 2) ^ c2); - - seed ^= extract(state->z2, 2); - state->z3 = insert(state->z3, start + 0, seed); - state->z3 = insert(state->z3, start + 1, seed ^ c1); - state->z3 = insert(state->z3, start + 2, (seed << 3) ^ c1); - state->z3 = insert(state->z3, start + 3, (seed << 2) ^ c2); - - seed <<= 4; - seed += 3; - seed ^= extract(state->z1, 3); - state->z4 = insert(state->z4, start + 0, seed); - state->z4 = insert(state->z4, start + 1, seed ^ c1); - state->z4 = insert(state->z4, start + 2, (seed << 3) ^ c1); - state->z4 = insert(state->z4, start + 3, (seed << 2) ^ c2); - - return seed; -} - static inline void seed_rng(varying RNGState * uniform state, - uniform unsigned int seed) { - if (programCount == 1) { - state->z1 = seed; - state->z2 = seed ^ 0xbeeff00d; - state->z3 = ((seed & 0xffff) << 16) | (seed >> 16); - state->z4 = (((seed & 0xff) << 24) | ((seed & 0xff00) << 8) | - ((seed & 0xff0000) >> 8) | (seed & 0xff000000) >> 24); - } - else { - seed = __seed4(state, 0, seed); - if (programCount == 8) - __seed4(state, 4, seed ^ 0xbeeff00d); - if (programCount == 16) { - __seed4(state, 4, seed ^ 0xbeeff00d); - __seed4(state, 8, ((seed & 0xffff) << 16) | (seed >> 16)); - __seed4(state, 12, (((seed & 0xff) << 24) | ((seed & 0xff00) << 8) | - ((seed & 0xff0000) >> 8) | (seed & 0xff000000) >> 24)); - } - } + unsigned int seed) { + state->z1 = seed; + state->z2 = seed ^ 0xbeeff00d; + state->z3 = ((seed & 0xffff) << 16) | (seed >> 16); + state->z4 = (((seed & 0xff) << 24) | ((seed & 0xff00) << 8) | + ((seed & 0xff0000) >> 8) | (seed & 0xff000000) >> 24); } static inline void seed_rng(uniform RNGState * uniform state, diff --git a/tests/rand-distrib-1.ispc b/tests/rand-distrib-1.ispc index a53cef12..3a23a917 100644 --- a/tests/rand-distrib-1.ispc +++ b/tests/rand-distrib-1.ispc @@ -3,7 +3,7 @@ export uniform int width() { return programCount; } export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) { RNGState state; - seed_rng(&state, 1); + seed_rng(&state, programIndex); int count[32]; for (uniform int i = 0; i < 32; ++i) count[i] = (b == 5.) ? 0 : 1; diff --git a/tests/rand-distrib.ispc b/tests/rand-distrib.ispc index edf24f2b..393ec063 100644 --- a/tests/rand-distrib.ispc +++ b/tests/rand-distrib.ispc @@ -3,7 +3,7 @@ export uniform int width() { return programCount; } export void f_f(uniform float RET[], uniform float aFOO[]) { RNGState state; - seed_rng(&state, 1); + seed_rng(&state, programIndex); float sum = 0; uniform int iters = 40000; for (unsigned int i = 0; i < iters; ++i)