3 ms·
And IIRC compilers have been somewhat chilly about cmov because (iirc) it can’t be speculatively executed.
by masklinn 5y ago
And IIRC compilers have been somewhat chilly about cmov because (iirc) it can’t be speculatively executed.
- ncmncm 5y agoIt 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.
- tialaramex 5y agoCMOV 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).
- gerbenst 5y agoThe 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.
- masklinn 5y ago> Many vulnerabilities stem from accessing/modifying memory that should not be accessed/modified. So a complement to the likely/unlikely annotations?
- bobthebuilders 5y agoGot a link?
- ncmncm 5y agohttps://cantrip.org/swap_if.pdf 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 https://wg21.link/p1144 explores that territory too. Gcc has weird limits on generating CMOV instructions to implement this sort of optimization.