It is currently Tue May 21, 2013 1:36 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Wed Nov 16, 2011 11:31 pm 
Offline
Snes9x White Belt

Joined: Tue Nov 15, 2011 12:12 am
Posts: 27
I'm not a very experienced programmer, so the following question/suggestion may come as silly.

Looking at the Snes9X source code, I came across an interesting and important line:
Code:
(*Opcodes[Op].S9xOpcode)();


It seems function pointers are used for executing opcodes. I am tempted to ask, wouldn't a switch statement be (at least somewhat) faster ? I base this statement on a quote I read some time ago:

Quote:
[to optimize a VM] use a large switch-case instead of a table of function pointers (the compiler will optimize to a jump table, and you remove the overhead of actually calling the function)
(source: http://stackoverflow.com/questions/4708 ... erformance)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2011 7:43 pm 
Offline
Snes9x White Belt

Joined: Tue Nov 15, 2011 12:12 am
Posts: 27
Nevermind. It seems optimizing compilers do a very good job of reducing this overhead. For example with MSVC 2010 the generated assembly for opcode calling is:
Code:
      (*Opcodes[Op].S9xOpcode)();
004339F5 8B 0C B7             mov         ecx,dword ptr [edi+esi*4] 
004339F8 FF D1                call        ecx 

and the only overhead in opcode implementation functions is a "ret" instruction at the end of their code.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group