Hacker News new | past | comments | ask | show | jobs | submit login

Lots of code has apparent branches which compilers effectively optimize. An easy example is integer signbit:

   int isignbit(int x) { return x < 0 ? 1 : 0; }
which is reliably optimized to logical right shift.

Are there any code patterns where the compiler emits branches that are not apparent in the code? Notwithstanding overflow checks, etc.




That's a good point, but a bad example since 'x < 0 ? 1 : 0' is just the same as 'x < 0', which is also be implemented (on x86) as a CMP followed by SETcc.


Some targets don't support integer division/remainder or some floating point ops in hardware and automatic vectorization can add/remove branches in places that won't be easily predictable.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: