|
|
|
|
|
by ncmncm
1650 days ago
|
|
Thank you. It appears Gcc won't put two cmov writes to memory in a block. Thus, void swap_if(bool c, int& a, int& b) {
int ta = a, tb = b;
a = c ? tb : ta;
b = c ? ta : tb;
}
is very slow, under Gcc, when c is poorly predicted, as is typical when e.g. partitioning for quicksort. But how well it will be predicted depends on input data.[0] https://godbolt.org/z/j5W9dMjYE |
|
Edit: compiling your code without modifications, but with `-Os` also gives two cmov's: https://godbolt.org/z/r86azb7be