Photo: Unknown author Unknown author or not provided · Public domain · Wikimedia Commons
General Tech

Switch Lowering in GCC

The GCC compiler can optimize switch statements by transforming them into decision trees or jump tables, but the choice of optimization depends on the sparsity of the case values. The compiler uses a threshold of around 8 jump table entries per case label to decide when to use a jump table. This means that if there are more than 8 distinct case values, the compiler will use a jump table. However, if the case values are sparse, the compiler may choose to use a decision tree instead. The compiler can also recognize dense subsets of cases and use a jump table for those specific cases.

Read the full article at xoranth.net →