> The switch in sparse_8 could be simplified by dividing x by eight before the jump. Interestingly, gcc doesn't find this simplification.

It could not because that would ensure that 7 values for each case would be handled by function calls instead of the default case - 0/8 is 0, but 3/8 is also 0

All the values are divisible by 8, so it could do it like this:

    cmp  eax,40
    ja   <return 0>
    test eax,7
    jnz  <return 0>
    jmp  JumpTable[rax]