Re:A bug that doesn’t exist on x86: Exploiting an ARM-only r...
by vlovich123 on Tuesday October 26, 2021 @03:02PM
(#29004740)
Correct. `-Ofast` claim to fame is it enables `-ffast-math` which is why it has huge warning signs around it in the documentation. `-ffast-math` turns on associativity which is problematic for Kahan summation. Rather than sprinkling in volatiles which pessimizes the compiler to no end, I would recommend annotating the problematic function to turn off associativity [1][2].
Something like:
[[gnu::optimize("no-associative-math")]]
double kahanSummation() {
...
}
That way the compiler applies all the optimizations it can but only turns off associative math. This should work on Clang & GCC & be net faster in all cases.This is what I mean by "If you're sprinkling volatile around, you probably aren't doing what you want" and are just cargo culting bad advice.
[1] https://stackoverflow.com/questions/26266820/in-clang-how-do... [2] https://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Function-Attrib...
Re:A bug that doesn’t exist on x86: Exploiting an ARM-only r...
by hermitdev on Tuesday October 26, 2021 @06:28PM
(#29007181)
I hope this isn't the actual "real" code, because you've got undefined behavior before you even have to worry about the associativity optimizations. There's an uninitialized read of 'kahan_c' on the first loop iteration.
Changing the three kahan_* variables to volatile makes this work (slowly) with -Ofast.