28-Feb-2013 21:38, deadalnix пишет:
On Thursday, 28 February 2013 at 17:13:36 UTC, Dmitry Olshansky wrote:
No as a compiler will take it (or may depending on its brain) that 0
is what you want to test *first*. It may speed things up if branch is
almost always taken but its not the case with sentinel. Thus its jsut
dead code that needs to be decoded, evalutated and skipped (as
predicated) *before* doing switch jump.

In fact some people avoid the overhead of switch by placing one or two
of highly-frequent branches with tests before the switch (thus
avoiding indirect branch it entails in these frequent cases).

That won't work as expected with LLVM and full optimizations, as it will
combine everything in a switch, unless you use branch weight, in which
case it can do the reverse : extract common cases from the switch.

See : http://llvm.org/docs/BranchWeightMetadata.html

GCC does something similar.

This is another example of how people think they are doing high level
assembly when in fact, the compiler is changing everything behind their
back, and not doing at all what they think.

Depends on the brains of compiler like I said. BTW it can't know the most frequent branches so jump-table may be actually slower (in some cases though they are niche).

--
Dmitry Olshansky

Reply via email to