[virtmach] switch vs dispatch table (was Your VM)

Thomas Fjellstrom virtmach@iecc.com
Tue, 29 May 2001 13:36:00 -0600


MickaŽl Pointier wrote:
> 
> > > > 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.
> > >
> > > Most compilers will generate a range check before the jump, where as a
> hand
> > > coded jump table can assume that the data is in range.  Of course, its
> very
> > > hard to say, as we haven't even mentioned what language this VM might be
> > > implemented in...
> > >
> >
> > Personally I was thinking about C and gcc when I asked the question...
> 
> You may want to take a look at this page:
> 
> http://www.complang.tuwien.ac.at/forth/threaded-code.html
> 
> Toward the end there are some interesting considerations about the various
> way to implement the so called "threaded code".
> 

Good page isn't it? I've already implemented the GNU C's Lables as
values
style threading. It works well but I've never had the time or patients
to keep it up to date with the rest of the VM. (I should just write
a perl script to enerate the two...)

-- 
"Computer programmers don't byte, they nybble a bit."
Thomas Fjellstrom
tfjellstrom@home.com
http://strangesoft.net/