-CswMinLF: Minimum Load Factor for Switch Tables

Group

CODE GENERATION

Scope

Function

Syntax
  -CswMinLF<number> 
  
Arguments

<number>: a number in the range of 0 - 100 denoting the minimum load factor

Default

Backend-dependent

Defines

None

Pragmas

None

Description

Allows the Compiler to use tables for switch statements.

Note: This option is only available if the compiler supports switch tables.

Normally the Compiler uses a table for switches with more than about eight labels, provided the table is between 80% (minimum load factor of 80) and 100% (maximum load factor of 100) full. If there are not enough labels for a table or the table is not full, the Compiler generates a branch tree (tree of if-else-if-else). This branch tree, like an `unrolled' binary search in a table, quickly evaluates the associated label for a switch expression.

Using a branch tree instead of a table improves code execution speed, but may increase code size. In addition, because the branch tree itself uses no special runtime routine for switch expression evaluation, debugging is more seamless.

Specifying a load factor means that tables generate in specific `fuel' status:

Listing: Specifying Table Load Factor


switch(i) {
  case 0: ...

  case 1: ...

  case 2: ...

  case 3: ...

  case 4: ...

  //  case 5: ...

  case 6: ...

  case 7: ...

  case 8: ...

  case 9: ...

  default

}

The above table is 90% full (labels for `0' to `9', except for `5'). Setting the maximum load factor to 100% and the minimum load factor for the above case to 90%, this still generates a table. But setting the minimum load factor to 95% produces a branch tree.

To guarantee that tables generate for full switch tables only, set the minimum and maximum table load factors to 100:

-CswMinLF100 -CswMaxLF100.

See also

Compiler options :