logoalt Hacker News

tredre3today at 4:00 PM2 repliesview on HN

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.


Replies

misevtoday at 4:12 PM

You could rewrite it to

    int* ptr = ((v != 0) * lwr) + ((v == 0) * rwr);
I doubt it would be faster than the ternary though.
xyzsparetimexyztoday at 4:25 PM

Does any standard library have a glsl-like select(condition, true_val, false_val) that is more or less guaranteed to correspond to a csel?