News for hackers. Stuff that matters.
Re:Your code is fast – if you're lucky by xyzsparetimexyz on Saturday July 11, 2026 @11:45AM (#48873041)
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;

Re:Your code is fast – if you're lucky by tredre3 on Saturday July 11, 2026 @12:00PM (#48873189)
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.
Re:Your code is fast – if you're lucky by misev on Saturday July 11, 2026 @12:12PM (#48873293)
You could rewrite it to

    int* ptr = ((v != 0) * lwr) + ((v == 0) * rwr);
I doubt it would be faster than the ternary though.
Re:Your code is fast – if you're lucky by xyzsparetimexyz on Saturday July 11, 2026 @12:25PM (#48873406)
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?