Files
ispc/tests/short-circuit-4.ispc
Matt Pharr e19f4931d1 Short-circuit evaluation of && and || operators.
We now follow C's approach of evaluating these: we don't evaluate
the second expression in the operator if the value of the first one
determines the overall result.  Thus, these can now be used 
idiomatically like (index < limit && array[index] > 0) and such.

For varying expressions, the mask is set appropriately when evaluating
the second expression.

(For expressions that can be determined to be both simple and safe to
evaluate with the mask all off, we still evaluate both sides and compute
the logical op result directly, which saves a number of branches and tests.
However, the effect of this should never be visible to the programmer.)

Issue #4.
2012-01-30 05:58:41 -08:00

22 lines
454 B
Plaintext

export uniform int width() { return programCount; }
uniform int * uniform ptr;
bool crash() {
return *ptr > 0;
}
export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) {
float a = aFOO[programIndex];
uniform float a0 = aFOO[0], a1 = aFOO[1];
if (a0 > a1 && crash())
RET[programIndex] = 0;
else
RET[programIndex] = 1;
}
export void result(uniform float RET[]) {
RET[programIndex] = 1;
}