Files
ispc/tests/rdrand-3.ispc
Matt Pharr 411d5b44ef Add ISPC_HAS_RAND definition on targets that have a HW RNG.
This lets us check for a functioning rdrand() call in the stdlib
more reliably.  Fixes issue #333.
2012-10-03 09:18:12 -07:00

26 lines
578 B
Plaintext

export uniform int width() { return programCount; }
export void f_f(uniform float RET[], uniform float aFOO[]) {
#ifndef ISPC_HAS_RAND
RET[programIndex] = 1;
#else
int lessHalf = 0, moreHalf = 0;
for (uniform int i = 0; i < 1024*1024; ++i) {
float r = -1;
while (!rdrand(&r))
;
if (r < 0.5) ++lessHalf;
else ++moreHalf;
}
float r = (double)lessHalf / (double)(lessHalf + moreHalf);
RET[programIndex] = (r >= .49 && r < .51);
#endif
}
export void result(uniform float RET[]) {
RET[programIndex] = 1;
}