3 ms·
There was a time (late 90s) when GCC would optimize conditionals in an asymmetric way. Somebody will hopefully correct me, but I think the advice was to make co
by theoh 11y ago
There was a time (late 90s) when GCC would optimize conditionals in an asymmetric way. Somebody will hopefully correct me, but I think the advice was to make conditionals usually be true, for best performance. Since most coders would never hear about this asymmetry (though that's just my impression) it was a bizarre case of favoring one branch of a conditional over another for purely historical (machine code) reasons.
- xentronium 11y agoI think some optimizations are still possible based on likeliness of conditionals. http://stackoverflow.com/questions/109710/likely-unlikely-macros-in-the-linux-kernel-how-do-they-work-whats-their http://stackoverflow.com/questions/109710/likely-unlikely-ma...
- striking 11y agoI think now branch prediction on processors can go either way, just as long as it's biased one way or another. If it's not biased one way or another, try to reduce out branches into vectorizable instructions (or pray that GCC takes care of it for you). Branch prediction isn't a GCC thing, it's a processor thing. Observe this wonderful Stack Overflow question: http://stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-an-unsorted-array http://stackoverflow.com/questions/11227809/why-is-processin...