Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Branchless Equivalents of Simple Functions (2008) (hbfs.wordpress.com)
17 points by sytelus on Sept 25, 2015 | hide | past | favorite | 2 comments


glibc's abs() implementation is here: https://github.com/bminor/glibc/blob/master/stdlib/abs.c

It's the naive branching version (probably for platform independence?), but my installed GCC 4.9.3 does convert it to branchless cdq/xor trick on both -O3 and -O0.


Last time I looked the "naive"[1] version of fizzbuzz, when compiled with GCC or Clang, was converted to a branchless version (for x86 at least). I don't remember what -O level was needed thou.

[1] as is the if and modulo based way




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: