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.
This commit is contained in:
21
tests/short-circuit-1.ispc
Normal file
21
tests/short-circuit-1.ispc
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
export uniform int width() { return programCount; }
|
||||
|
||||
uniform int * uniform ptr;
|
||||
|
||||
uniform 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] = 1;
|
||||
else
|
||||
RET[programIndex] = 0;
|
||||
}
|
||||
|
||||
export void result(uniform float RET[]) {
|
||||
RET[programIndex] = 1;
|
||||
}
|
||||
Reference in New Issue
Block a user