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

Just a fair warning as someone who has made extensive use of this page in the past: many of these hacks often end up slower these days on modern CPUs than naive approaches. Especially the no-branch and no-multiply math ops.

As always, be sure to performance test your code if you're getting into obfuscating your algorithms to boost speeds.

That said, there are still plenty of real gems in there. And on that note, here's one of my favorite bit-twiddling hacks:

http://webcache.googleusercontent.com/search?q=cache:www.sla...

http://webcache.googleusercontent.com/search?q=cache:www.sla...

http://webcache.googleusercontent.com/search?q=cache:www.sla...

(these functions are for RGB555, but you can easily extend these to RGB888 ops.)




One place the branchless techniques can come in handy is with SIMD (or simulated SIMD by packing several small ints into longer ones.) A branchless algorithm that's 50% slower can pay for itself if you can process four elements at a time.

Agreed that performance testing is absolutely necessary, preferrably with something that can tell you not only where exactly the processor is spending its time but also whether it's spending its time computing or waiting on memory etc, whether branches are being predicted well...




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

Search: