logoalt Hacker News

craftkillertoday at 4:59 PM3 repliesview on HN

Here's an example of removing a branch that was posted to HN a little over a month ago: https://www.greyblake.com/blog/branchless-rust/


Replies

metabageltoday at 5:36 PM

From the article:

=====

Should you go branchless?

Most of the time, no. Branchless code is harder to read and easier to get wrong. Besides, compilers know a lot of tricks and already do a lot of this work for us.

Only when a profiler points at a hot loop, and the loop contains a branch on unpredictable data this technique can pay off big.

metabageltoday at 5:04 PM

OK, but the code with the branch is easier to understand.

show 2 replies
cestithtoday at 5:06 PM

That's a really nice example. Thanks.