It is currently Tue Dec 12, 2017 10:35 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Sep 07, 2005 5:58 pm 
Offline

Joined: Thu Aug 25, 2005 7:36 pm
Posts: 4
The CPU emulation use over 128 opcodes.
It will be a large switch.
How to use jump table instead of if - else - if - else - if - else.
Is there any compile option of VC6?
Who can help me?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 6:39 pm 
Offline
Site Admin
User avatar

Joined: Mon Sep 20, 2004 6:04 am
Posts: 3487
Location: Indianapolis
Use switch, case and break. I believe that will compile into a jump table.

http://www.acm.uiuc.edu/webmonkeys/book/c_guide/1.6.html#switch


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 10:12 am 
Offline
User avatar

Joined: Thu Oct 21, 2004 4:02 pm
Posts: 210
Location: San Diego
I don't think there is any way you can force it to use a jump table, it's one of those decisions the compiler will make on it's own. There are a couple of things that seem to affect this that you have control over, however. A very large switch statement will usually compile into a jump table, and there are optimization flags you can use which may affect this. In gcc it's the -O2 and -O3 etc. flags, I don't know about VC as I can't stand using that environment but I'm sure there are similar options.
Make sure you look at the disassembly and verify the compiler is doing what you expect.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 11:37 am 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 3076
Location: Brazil
I don't use switch/case statements, but blocks. Two jumping tables - one for the addressing mode, other for the opcode.

_________________
Zepper
RockNES developer


Top
 Profile  
 
PostPosted: Thu Sep 08, 2005 12:21 pm 
Offline

Joined: Mon Nov 22, 2004 3:24 pm
Posts: 162
Location: Sweden
If you intend to use a switch then make sure to keep the cases in order and without gaps (this improves performance on VC6 at least). Hopefully the compiler will be intelligent to skip the range check (default case) if you cover all possible byte patterns..

And study the generated assembly code if you can, at least I wouldn't blindly trust the optimizer on vital decisions like this.


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: Google Adsense [Bot] and 7 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