ispc/ispc — Issue #159: switch: investigate alternative "varying" implementation approach
Author: mmp
Created: 2012-01-11 23:42:23+00:00
State: open
Labels: performance

Another option to consider for varying switch statements would be along the
lines of how we do calls to varying function pointers: conceptually, we
loop over all of the active lanes, pick one active lane, find the switch
expression value for that lane, and then set the mask to represent which
program instances have the same value of the expression. We could then
execute the code for a uniform switch expression, taking advantage of the
efficient code generation for those when there are many cases. Those lanes
would then be disabled and this process would continue with another
remaining active lane, until all lanes have been handled.

There is one tricky detail: ispc's program convergence guarantees. If we
have code like:

```
switch (x) {
case 0:
// ...
// NO "break" statement, fall through to next case
case 1:
// ...
}
```

Then if x has the value 0 for some program instances and has the value 1
for others, then when we enter the code in the switch for case 1, the set
of running program instances should be the union of those two sets of
program instances. The approach outlined above wouldn't provide this. (So
this needs to be figured out.)