[Bug libstdc++/85466] Performance is slow when doing 'branchless' conditional style math operations
cpphackster at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sat Apr 21 04:25:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85466
--- Comment #15 from Daniel Elliott <cpphackster at gmail dot com> ---
Good catch johnathan on the return type of max. (PS also enjoyed your accu talk
on youtube).
I also have been messing around with the benchmark a bit and have come to the
conclusion that the sign function and the max isn't really necesary. simple
ternary operators seems to do a better job.
However, gcc still seems to be slower in these cases compared to clang.
Ive attached benchmarkv2 which on my ivy bridge 2013 macbook pro gets....
GCC:
ifStandard 600741 ns 600594 ns 1056
ifNoConditional 191043 ns 191000 ns 3694
Clang:
ifStandard 88777 ns 88726 ns 7439
ifNoConditional 89818 ns 89777 ns 7910
Interestingly for the gcc case, if I return float from the when_greater_than
function (which is just doing x > y ? 1: 0; then it matches gcc ifStandard
speed exactly but if I return a float then goes down to the ~191000 ns speed
shown above. But still not as fast as both clang cases.
Have to say this is a lot of fun and thanks everyone for looking at this!
More information about the Gcc-bugs
mailing list