4 ms·
See my other comment (https://news.ycombinator.com/item?id=8906866 https://news.ycombinator.com/item?id=8906866) The compiler can optimize the layout of the ba
by ot 12y ago
See my other comment (https://news.ycombinator.com/item?id=8906866 https://news.ycombinator.com/item?id=8906866)
The compiler can optimize the layout of the basic blocks according to its beliefs (or hints) on the branch probabilities, but it won't move a code path to a separate function. I don't know if this could be done in compliance with the standard, but I haven't seen any compiler do it.
EDIT: I stand corrected, looks like GCC 4.9 can do it (http://goo.gl/amM4Et http://goo.gl/amM4Et). Still, it didn't do it when I needed it :)
- DannyBee 12y agoFunction outlining can be done, if it's not being done, you don't have the right options or it's deciding it's not profitable. (and FWIW, ICC has done this for at least 8 years)
- repsilat 12y agoWhy put it into a separate function? You could just movie it to the end and jump there and back,saving the call overhead.
- Rusky 12y agoIt makes the function smaller, making it easier to inline. This might matter depending on how easy it is for the compiler to do partial inlining.
- DannyBee 12y agoCall overhead would be nil, since it created the function, and thus it does not have to follow normal argument passing behavior :) In effect, it will just be a bunch of gotos.