-CswMaxLF: Maximum Load Factor for Switch Tables

Group

CODE GENERATION

Scope

Function

Syntax
  -CswMaxLF<number> 
  
Arguments

<number>: a number in the range of 0 to 100 denoting the maximum load factor.

Default

Backend-dependent.

Defines

None

Pragmas

None

Description

Using this option changes the default strategy of 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 filled, 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 may be 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 filled to 90% (labels for `0' to `9', except for `5'). Setting the minimum load factor to 50% and the maximum load factor for the above case to 80%, a branch tree generates instead a table. But setting the maximum load factor to 95% produces a table.

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

-CswMinLF100 -CswMaxLF100.

See also

Compiler options: