Just came across this (compiled code for processing switch statements)
// compare case value 1
// jump if eq
// compare case value 2
// jump if eq
// compare case value 3
// jump if eq
// compare case value 4
// jump if eq
// ...
//
What if there a lot of cases ?
There's got to be a better way. Something like:
// rep: cmpswne ; repeat compare consecutive words for equality
// jmp adrtbl[reg] ; jump when a match occurs
OR
rep: cmpswAndJmp
RTF
To post a message, send it to: f...@yahoogroups.com
To unsubscribe, send a blank message to: f...@yahoogroups.com

(You need to be a member of fpga-cpu -- send a blank email to fpga-cpu-subscribe@yahoogroups.com )
Having investigated some while ago, what a number of compilers do with switches, it looked
like most compilers mix jump tables and single jumps based on how many consecutive entries
there are, number of groups and how sparse some entries are. It seems the compilers looked
at moved to jump tables at about or 6 entries depending on speed and size optimisation
directives.
If you have never done this with a good compiler, such as gcc, it is worth doing to
witness what the code generators will do with switches.
----- Original Message -----
From: Eric Smith
To: f...@yahoogroups.com
Sent: Friday, January 18, 2008 4:07 PM
Subject: Re: [fpga-cpu] Case statement accelerations
Rob wrote:
> Just came across this (compiled code for processing switch statements)
> // compare case value 1
> // jump if eq
> // compare case value 2
> // jump if eq
Yes, in fact many compilers will generate jump tables if the case values
are in a consecutive or mostly-consecutive range. Some compilers have
options or pragmas to allow control of that feature.
[Non-text portions of this message have been removed]
To post a message, send it to: f...@yahoogroups.com
To unsubscribe, send a blank message to: f...@yahoogroups.com

(You need to be a member of fpga-cpu -- send a blank email to fpga-cpu-subscribe@yahoogroups.com )