[virtmach] Your VM

David Rush virtmach@iecc.com
28 May 2001 14:17:55 +0100

jlane@nwlink.com writes:
> Fjellstrom (?) wrote:
> > Now I have a question: does any one know for sure
> > if an array of function pointers is faster than
> > a switch case? I know threaded code is faster but
> > is an function pointer array? (will it help the
> > cpu cache enough to make a difference?)
> Assuming that the switch and array are both dense, i.e.
> all or nearly all possible positions in the table are
> in use, then it depends on which compiler you are using.
> Many compilers will generate an indirect jump through a
> table of pointers for a dense switch.  Generally, the
> compiler can generate better code for this internally
> than can be written in source code, so the switch version
> is likely to be faster.

It's worth noting that your most-used instructions may benefit from
being if-dispatched depending on underlying CPU issues. In particular,
CPUs with branch predictors can't use them on jump tables, so you can
easily get I-cache misses and pipeline stalls. Additionally, if
branches can often take advantage of CPU delay slots. But all of that
comes under the heading of 'performance tuning'; you have to do it for
each machine your VM will run on, but that's why you wrote a VM
anyway, isn't it? To isolate your machine dependencies...

david rush
Communism is inequality, but not as property is. Property is
exploitation of the weak by the strong. Communism is exploitation of
the strong by the weak.
	-- What is Property? (Pierre-Joseph Proudhon)