4 ms·
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.
by gerbenst 5y ago
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.
- CJefferson 5y agoI agree with the first part -- I implemented the movable std::sort for g++, and I found it very hard to convince the compiler to keep the pivot in a register (although I did write it over 10 years ago, maybe the compiler would do a better job by now!)
- gerbenst 5y agohttps://godbolt.org/z/zPWr73qjc 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.
- CJefferson 5y agoI think life gets harder when you have to deal with iterators, and have to use iterator::reference (which might not be a raw C++ reference, although it almost always is in practice).