Hacker News new | ask | show | jobs
by warrenmar 3723 days ago
Depending on how you structure your loops, things can be optimized on how it hits the cache and reads contiguous memory addresses.
1 comments

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.
I 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-processin...

I think some optimizations are still possible based on likeliness of conditionals.

http://stackoverflow.com/questions/109710/likely-unlikely-ma...