IT lexicon › Programming › Jump table

Jump table

Programming På svenska → Updated: 2026-11-05

A table of code addresses that lets a switch jump straight to the right case with one indirect jump, instead of comparing case by case.

When the cases are dense, say 0 to 50, the compiler emits a bounds check, uses the value as an index into the table and jumps. The cost is constant however many cases there are. Sparse values like 1, 1000 and 70000 would produce a mostly empty table, so there the compiler builds a binary search tree of comparisons instead, or bit tests when there are only a few cases. Where the line falls is down to heuristics about density and case count.

Spectre changed the arithmetic. Indirect jumps can be poisoned in the branch predictor, and with retpolines every one of them became expensive. The Linux kernel therefore asks GCC for more cases before it builds a table, and -fno-jump-tables turns them off altogether.

← Back to the lexicon