GCC picks a jump table over a comparison tree by counting comparisons, not labels (xoranth.net)
The post walks through GCC's lowering order: bit tests first, then jump tables, then a binary tree. The speed rule allows a table up to 8 times the number of comparisons it replaces.
A commenter who builds compilers says GCC and Clang still lack perfect hashing for large sparse switches, and one reader explains why the missed divide-by-eight is actually correct.
Sign in to save