Add foreach and foreach_tiled looping constructs

These make it easier to iterate over arbitrary amounts of data
elements; specifically, they automatically handle the "ragged
extra bits" that come up when the number of elements to be
processed isn't evenly divided by programCount.

TODO: documentation
This commit is contained in:
Matt Pharr
2011-11-30 13:17:31 -08:00
parent b48775a549
commit 8bc7367109
32 changed files with 1120 additions and 78 deletions

29
tests/foreach-18.ispc Normal file
View File

@@ -0,0 +1,29 @@
export uniform int width() { return programCount; }
export void f_f(uniform float RET[], uniform float aFOO[]) {
#define NA 3
#define NB 8
uniform int a[NA][NB];
for (uniform int i = 0; i < NA; ++i)
for (uniform int j = 0; j < NB; ++j)
a[i][j] = 0;
foreach_tiled (i = 0 ... NA, j = 0 ... NB) {
a[i][j] += 1;
}
uniform int errs = 0;
for (uniform int i = 0; i < NA; ++i)
for (uniform int j = 0; j < NB; ++j)
if (a[i][j] != 1) {
++errs;
}
RET[programIndex] = errs;
}
export void result(uniform float RET[]) {
RET[programIndex] = 0;
}