The current implementation of table switches is messy and also causes problems for call-return based prediction on Intel processors (ie we implement tableswitches by modifying the PC value on the stack). I believe the following is more optimal, it uses an out-of-line thunk routine on IA32 and just an EIP move on x86-64:
T0 = getPCThunk() or RIP less offset from start of method
T0 += [T0 + m<<2 + tableDisplacement]
JMP T0
alignment NOP
tableDisplacement:
OFFSET 0 (case 0 target)
OFFSET 1 (case 1 target)
...
OFFSET n (case n target)
The current implementation of table switches is messy and also causes problems for call-return based prediction on Intel processors (ie we implement tableswitches by modifying the PC value on the stack). I believe the following is more optimal, it uses an out-of-line thunk routine on IA32 and just an EIP move on x86-64:
T0 = getPCThunk() or RIP less offset from start of method
T0 += [T0 + m<<2 + tableDisplacement]
JMP T0
alignment NOP
tableDisplacement:
OFFSET 0 (case 0 target)
OFFSET 1 (case 1 target)
...
OFFSET n (case n target)