ispc/ispc — Issue #157: switch: generate more efficient code for "default" with varying switches
Author: mmp
Created: 2012-01-11 23:41:37+00:00
State: open
Labels: performance

When we come to a "default" label in a "varying" switch statement, we need
to check to see if the switch expression's value is not equal to the value
of any of the other case statements. Currently, this is implemented in the
obvious way, by comparing to each of the case statement values.
For switch statements with large numbers of case labels, this may be
inefficient. There are a number of ways we could pursue to optimize the
code for this check.

For example, if a number of case labels cover a contiguous set of integer
values, we can check to see if the value under consideration is greater than
or equal to the lowest such integer value and less than or equal to the
highest such integer value.

Alternatively, we might be able to do something with perfect hashing and a
hash table of the case label values that are present.