ispc/ispc — Issue #158: switch: more efficient code for varying switch with many cases
Author: mmp
Created: 2012-01-11 23:42:01+00:00
State: open
Labels: performance

The code generated for switch statements with "varying" test expressions
roughly corresponds to running through all of the case/default statements
in program order, updating the mask at each case/default label to turn on
the lanes that match the corresponding label. (For labels with complex
code after them, we do jump to the following label if the mask is all off.)
Nevertheless, for large numbers of labels, this approach is likely to be
sub-optimal.

One opportunity is to bracket the relevant labels; if we can determine the
first case/default that matches the switch expression and the last one
(accounting for labels that aren't terminated with break statements), then
we can start running at the first label and exit out at the last one.