HackerTrans
TopNewTrendsCommentsPastAskShowJobs

gerbenst

no profile record

comments

gerbenst
·4 ปีที่แล้ว·discuss
The key point of this article (I'm the author) is that even if cmov would be like 50 cycle latency instruction and the penalty of a mispredicted branch is 0 (ie. after the cpu sees a branch is mispredicted it would immediately start executing the instructions from the correct branch), than cmov would still be faster on modern CPU's.

Because in branchless quicksort, no matter how long it takes to figure out where the element has to go relative to the pivot it doesn't obstruct the CPU's ability in this algorithm to start working on the next element the next cycle.
gerbenst
·4 ปีที่แล้ว·discuss
https://godbolt.org/z/zPWr73qjc

Here is an implementation. This should work with all types. Unfortunate I had to annotate with restrict, but a small price to pay.
gerbenst
·4 ปีที่แล้ว·discuss
it's not difficult to swap the pivot with the last element and have the compiler figure out it can keep pivot in register most of the time.