logoalt Hacker News

xyzsparetimexyztoday at 3:45 PM1 replyview on HN

What if you wrote this in a branchless way?

bool v = BLQS_CMP(x, piv);

int* ptr = v ? lwr : rwr;

*ptr = x;

ptr += int(v) * 2 - 1;


Replies

tredre3today at 4:00 PM

The ternary isn't guaranteed to be branchless. In your case it should almost always be on a modern compiler, but it really shouldn't be present in what one would call branchless code.

show 2 replies