[Tfug] GCC optimizations
Bexley Hall
bexley401 at yahoo.com
Thu Oct 19 12:58:24 MST 2006
Hi,
--- Robert Hunter <hunter at tfug.org> wrote:
> It seems that GCC generates either binary search or
> jump table code based on a hueristic which considers
> the number of cases and the range of case values.
Makes sense...
> For very small numbers of cases, or for very
> large ranges of values, gcc generates binary search
> code.
Hmmm... for small numbers of cases, it seems like the
extra tests for a binary search would just get in
the way. And, for pathological scenarios, probably
be counterproductive :< (of course, expecting a
machine to get *all* of these things right is
asking a lot -- easier for the application designer
to put some smarts into the structure of the code)
> Otherwise it generates a jump table.
> Previously I ran across some literature
> that discussed using different branching techniques,
> such as perfect hashes, but I don't have a
reference.
>
> The article linked below addresses gcc for the cell,
> but I think it is generally relevant.
>
>
http://www.cellperformance.com/articles/2006/04/programming_with_branches_patt.html#rule_3
*Excellent* reference! I will bookmark this for
future reference. Thank you!
I think my best bet is to coax the compiler into
generating a *small* jump table and ensure that
all cases have contiguous values (no holes).
It would be hard to do much better by hand -- unless
I statistically modeled the relative frequencies of
each branch (case) and tuned the code to that
distribution... :<
Thanks!
--don
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the tfug
mailing list