Re: [Sablevm-user] SableVM question
Brought to you by:
egagnon
From: Marcel A. <ma...@ca...> - 2000-08-29 01:40:44
|
Hi, Etienne M. Gagnon wrote (eg...@j-...) > Hi Marcel. > > Marcel Ammerlaan wrote: > > My question is: why use goto instead of switch()? > > The concept of using goto's in the interpreter loop is usually referred > to as "threaded" interpretation. This name originates, if I am right, > from implementations of the FORTH language. > > The short answer to your question is: because it's (usually) much > faster. But, your experiment suggests that this is not the case... I > would be very interested in looking at your small benchmark program, to > see if there's something wrong with it. Would it be possible to send a > copy of it on the list? (This shouldn't be a long program, I guess). > > The reason "labels as values" were added in gcc was explicitly for cases > like interpreter loops. Here's some excerpt from gcc's documentation: > > "Another use of label values is in an interpreter for threaded code. > The labels within the interpreter function can be stored in the threaded > code for super-fast dispatching." Yeah, I read that too, that's what made me wonder in the first place. Although a C-compiler could probably better optimize a plain switch() statement (it's a higher level description of the same thing). Here is the result from a test-run I've got from a switch() vs. goto implementation: rincewind:~/src/pleurvm$ gcc -O2 -o test test.c rincewind:~/src/pleurvm$ time ./test switch! real 0m6.798s user 0m6.770s sys 0m0.030s rincewind:~/src/pleurvm$ gcc -O2 -o test2 test2.c rincewind:~/src/pleurvm$ time ./test2 goto! real 0m27.194s user 0m27.020s sys 0m0.010s I've included the source code (it's just a little interpreter which executes some random noise from /dev/random, hence the benchmark size. Opcode 0 means exit the loop). Marcel Ammerlaan ps. does any one know an alternative to GCC, it seems to mishandle my own little JVM making it crash in the long run. I want to double check with another C compiler before jumping to conclusions. -- Don't let people drive you crazy when you know it's in walking distance |