[virtmach] Switch vs. Jump Tables?

Lars Szuwalski lasz97ab@student.cbs.dk
Tue, 14 Nov 2000 19:01:22 +0100

> I've never look at the ASM code generated by an optimizing compiler for
> switch statement, but I'd assume it would produce some form of efficient
> jump table anyway.  And you would't have the overhead of a pointer
> indirection and fn call for each virtual instruction.  Has anyone looked
> into this in more detail?

I don't have actual documentation on this, but "swicth's" I have looked at
all turned in to some sort of jump-tables (VC++ 6.0) when compiled (don't
know how gcc does it). The reason for this seems straigh forward (to me at
least): Not only is it faster because of a lower "call/return" overhead, it
allso makes it easyer (read: possible) for the optimizer to choose which
variables to put into the machine-registers. This abillity may get lost if
you do function-pointer-calls (as the compiler/optimizer may not be able to
figure out what code is actully called at runtime. And even if it can, it
may be forced to preserve registers (to the stack or the heap) across
calls - making the call/return even more expensive). As I'm working on a
simular project myself (allso using a switch) I look forward to hearing more
about "First VM" and the internals of it :-)

Best regards!

Lars Szuwalski