buffer_num += (elements[i] < pivot);
Is this really branchless though? I'm curious what the generated assembler code looks like. buffer_num += (elements[i] < pivot);
Is this really branchless though? I'm curious what the generated assembler code looks like.EDIT: You can see this here https://godbolt.org/g/ssy4am
The odd writing style of first doing all comparisons is intentional - it increases the parallelism and reduces the data dependency in the generated code. Note how all the colors are mixed through eachother: this is a good sign.
Also note that there are no branches at all in the generated code. It's 'straight' code that the CPU can just march through at full speed. This is what makes it so stupidly fast.
EDIT: To clarify, my example was completely contrived, I just reused your variable names for some sense of familiarity.