switch_cases_array

Optimizes a certain class of the switch statements so that a memory access to load the address, of the selected case in a switch statement, is eliminated.

Syntax
#pragma switch_cases_array on | off | reset
  
Remarks

Normally, a selected case in a switch statement is chosen by loading the address of the selected case from a table of addresses. In some cases it is desirable to select a case without loading the case address from a memory table of addresses.

This optimization takes a switch statement and creates a contiguous array of code representing each possible selectable case. The code for each case is identical in size. This implies that where no applicable case is specified, there are dummy cases consisting of NOP code. Dummy cases eventually branch to the default case. It also implies that applicable cases may be padded with NOPs to achieve uniform size among the cases. The effect of a contiguous array of case values is that the selected case is chosen by an index calculated by the multiplication of the case value and the uniform case size. No memory loads are required to select the proper case.

This pragma should be used with care since the possibility of huge code growth is possible (since dummy cases are inserted to fill gaps between the user specified cases). Ideally, this optimization could be used on switch statements that have case values closely related such that as few as possible dummy cases are added.

The pragma’s scope is a function, so all switch statements within a function are affected by this pragma.