←back to thread

180 points xnacly | 1 comments | | HN request time: 0.209s | source
Show context
userbinator ◴[] No.44567872[source]
Replacing the switch with an array index and a jump.

Compilers will compile switches to a branch tree, two-level jump table, or single-level jump table depending on density and optimisation options. If manually using a jump table is faster, you either have a terrible compiler or just haven't explored its optimisation settings enough.

replies(1): >>44568068 #
1. teo_zero ◴[] No.44568068[source]
But the compiler will always add the jump back to the top of the loop, so it's two jumps per cycle. Manual dispatch is one jump per cycle.