optimization of switch statements on i386

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I have a question regarding the compilation of switch statements for
i386 targets. What heuristics or algorithm does gcc use to decide
whether to use a binary search or a jump table? I'm specifically
interested in switch statements for a dense range of values and in
which the default: branch is unreachable.

I've tried a number of approaches in order to obtain a jump table, but
it seems gcc 4.x always ends up creating binary searches. For
instance, I've tried casting the switch value to a limited range enum
and placing a gcc_unreachable() in the default: case. A cursory
inspection of the source code also didn't reveal any documentation of
the strategy used. Does gcc have reason to believe that a binary
search is always faster? If so, is this true for all variants of i386?
Would it depend on the number of case arms?

Thanks for any insights you could provide.

 - Godmar

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux