27 ms·
> undefined behavior in C/C++ is that it simplifies the compiler’s job, making it possible to generate very efficient code in certain situations. I've been gro
by tedunangst 11y ago
> undefined behavior in C/C++ is that it simplifies the compiler’s job, making it possible to generate very efficient code in certain situations.
I've been growing more skeptical of this claim over time. First, more evidence would be nice instead of "some loops". What is a program (not a benchmark) that has an observable performance difference when compiled with and without -fwrap?
Second, it seems counter productive. The word is now out that if you use signed ints, the compiler is going to fuck you over. So now everybody is (or should be) using unsigned ints, and whatever optimization the compiler was performing, now it can't. A lot of grief for no progress.
- pcwalton 11y ago> I've been growing more skeptical of this claim over time. First, more evidence would be nice instead of "some loops". What is a program (not a benchmark) that has an observable performance difference when compiled with and without -fwrap? Google brings up this old message. It seems to affect the SPEC2000 suite fairly badly. SPEC2000 mostly measures real applications, such as gzip, and is not a series of microbenchmarks. http://www.archivum.info/autoconf-patches@gnu.org/2007-01/00027/Re:-changing-quot-configure-quot-to-default-to-quot-gcc-g-O2-fwrapv-...-quot.html http://www.archivum.info/autoconf-patches@gnu.org/2007-01/00...
- tedunangst 11y agoInteresting, though I still wonder to what extent this is a result of optimizations chasing SPEC. Alternatively, could similar optimizations be made to work with defined behavior? (How will rust fair with "less undefined" behavior?) As I mentioned, it's kind of crazy that I might substantially impair the performance of gzip by changing a few ints to unsigned.
- Verdex 11y agoI really like your second point. That's kind of a difficult failure case to try and mitigate. I've been vaguely concerned with how to ensure my C code avoids undefined behavior, but it didn't occur to me that I also need to watch out in being overly conservative because then I'll be causing the optimizers trouble. I'm not trying to disparage anyone who is actually able to be productive in a C environment, but I'm really hoping something like Rust is able take over that development space.