Short-circuit evaluation of ? : operator for varying tests.
? : now short-circuits evaluation of the expressions following the boolean test for varying test types. (It already did this for uniform tests). Issue #169.
This commit is contained in:
30
tests/foreach-double-1.ispc
Normal file
30
tests/foreach-double-1.ispc
Normal file
@@ -0,0 +1,30 @@
|
||||
|
||||
export uniform int width() { return programCount; }
|
||||
|
||||
uniform double one = 1;
|
||||
|
||||
void copy(uniform double dst[], uniform double src[], uniform int count) {
|
||||
foreach (i = 0 ... count)
|
||||
dst[i] = one * src[i];
|
||||
}
|
||||
|
||||
export void f_f(uniform float RET[], uniform float aFOO[]) {
|
||||
uniform int count = 200 + aFOO[1];
|
||||
uniform double * uniform src = uniform new uniform double[count];
|
||||
for (uniform int i = 0; i < count; ++i)
|
||||
src[i] = i;
|
||||
|
||||
uniform double * uniform dst = uniform new uniform double[count];
|
||||
copy(dst, src, count);
|
||||
|
||||
uniform int errors = 0;
|
||||
for (uniform int i = 0; i < count; ++i)
|
||||
if (dst[i] != src[i])
|
||||
++errors;
|
||||
|
||||
RET[programIndex] = errors;
|
||||
}
|
||||
|
||||
export void result(uniform float RET[]) {
|
||||
RET[programIndex] = 0;
|
||||
}
|
||||
21
tests/short-circuit-select-1.ispc
Normal file
21
tests/short-circuit-select-1.ispc
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
export uniform int width() { return programCount; }
|
||||
|
||||
uniform int * uniform ptr;
|
||||
|
||||
bool crashEven() {
|
||||
return (programIndex & 1) ? true : (*ptr > 0);
|
||||
}
|
||||
|
||||
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) {
|
||||
float a = aFOO[programIndex];
|
||||
float a0 = aFOO[0], a1 = aFOO[1];
|
||||
if (((programIndex & 1) == 0) || crashEven())
|
||||
RET[programIndex] = 1;
|
||||
else
|
||||
RET[programIndex] = 0;
|
||||
}
|
||||
|
||||
export void result(uniform float RET[]) {
|
||||
RET[programIndex] = 1;
|
||||
}
|
||||
21
tests/short-circuit-select-2.ispc
Normal file
21
tests/short-circuit-select-2.ispc
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
export uniform int width() { return programCount; }
|
||||
|
||||
uniform int * uniform ptr;
|
||||
|
||||
bool crashEven() {
|
||||
return (programIndex & 1) ? true : (*ptr > 0);
|
||||
}
|
||||
|
||||
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) {
|
||||
float a = aFOO[programIndex];
|
||||
float a0 = aFOO[0], a1 = aFOO[1];
|
||||
if (((programIndex & 1) == 1) && crashEven())
|
||||
RET[programIndex] = 1;
|
||||
else
|
||||
RET[programIndex] = 2;
|
||||
}
|
||||
|
||||
export void result(uniform float RET[]) {
|
||||
RET[programIndex] = (programIndex & 1) ? 1 : 2;
|
||||
}
|
||||
20
tests/short-circuit-select-3.ispc
Normal file
20
tests/short-circuit-select-3.ispc
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
export uniform int width() { return programCount; }
|
||||
|
||||
float crashEven(uniform float a[]) {
|
||||
int offset = 0;
|
||||
return (programIndex & 1) ? a[offset] : a[offset+1000000];
|
||||
}
|
||||
|
||||
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) {
|
||||
float a = aFOO[programIndex];
|
||||
float a0 = aFOO[0], a1 = aFOO[1];
|
||||
if (((programIndex & 1) == 1) && (crashEven(aFOO) == 1))
|
||||
RET[programIndex] = 1;
|
||||
else
|
||||
RET[programIndex] = 2;
|
||||
}
|
||||
|
||||
export void result(uniform float RET[]) {
|
||||
RET[programIndex] = (programIndex & 1) ? 1 : 2;
|
||||
}
|
||||
Reference in New Issue
Block a user