News for hackers. Stuff that matters.
Re:Hoare’s Rebuttal and Bubble Sort’s Comeback by masklinn on Sunday January 30, 2022 @02:42AM (#30134912)
And IIRC compilers have been somewhat chilly about cmov because (iirc) it can’t be speculatively executed.
Re:Hoare’s Rebuttal and Bubble Sort’s Comeback by tialaramex on Sunday January 30, 2022 @04:24AM (#30135315)
CMOV is a win if the speculation won't work. HN regular Nathan Myers (ncmncm) wrote a proposal for C++ saying the compilers should offer a way to, in effect, signal that yeah, you really can't guess this one (thus, try CMOV).
Re:Hoare’s Rebuttal and Bubble Sort’s Comeback by gerbenst on Sunday January 30, 2022 @01:29PM (#30139689)
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.

Re:Hoare’s Rebuttal and Bubble Sort’s Comeback by masklinn on Sunday January 30, 2022 @04:50AM (#30135432)
> Many vulnerabilities stem from accessing/modifying memory that should not be accessed/modified.

So a complement to the likely/unlikely annotations?

Re:Hoare’s Rebuttal and Bubble Sort’s Comeback by bobthebuilders on Sunday January 30, 2022 @05:25AM (#30135613)
Got a link?
Re:Hoare’s Rebuttal and Bubble Sort’s Comeback by ncmncm on Sunday January 30, 2022 @08:34AM (#30137034)
https://cantrip.org/swap_if.pdf

It probably depends on a core language accommodation because bitwise-swapping objects, or even primitive elements of objects, with constructors is UB.

Arthur O'Dwyer's P1144 https://wg21.link/p1144 explores that territory too.

Gcc has weird limits on generating CMOV instructions to implement this sort of optimization.

Re:Hoare’s Rebuttal and Bubble Sort’s Comeback by ncmncm on Sunday January 30, 2022 @04:53PM (#30141513)
It seems possible that Rust could make better progress than C++ on incorporating this optimization into its standard library because it does not allow programmed move constructors, so "knows" more about its types. This is not assured, because it needs other declarative features that might not be in the core language yet, and might not be on the road map.

But running industrially important generic algorithms twice as fast as C++, automatically and without heroics, would be a Feather in Rust's Cap, and a Black Eye for C++. ("!!!!", as it were.) Or vice versa. Best would be if both got it, of course.

At present, both languages need heroics. I don't know of any other language where there is a reasonable prospect of getting such an optimization implemented generically, but that doesn't mean there aren't any.