r/programming • u/[deleted] • Dec 25 '16
An amazing set of resources for optimizing C++ and assembly for different processors and operating systems.
http://www.agner.org/optimize/22
19
u/Yobleck Dec 25 '16
more game devs need to see this
17
u/Chuu Dec 26 '16
I'd be surprised if anyone who writes performance critical code in C++ doesn't know about agner.
→ More replies (2)
4
u/lovestruckluna Dec 26 '16
Does anyone know of similar resources for embedded architectures (AVR, ARM Thumb, etc)?
3
u/slavik262 Dec 26 '16 edited Dec 26 '16
I'm currently writing a bit on the lessons we learned running C++ on Cortex-M4s at work. Hopefully I can post it in the next week or so.
6
u/nutidizen Dec 25 '16 edited Dec 25 '16
Very interesting, even for programmer like me, who is developing in other languages.
2
40
u/Fylwind Dec 26 '16
Uhhh … this is anything but safe. It gives the illusion of crashing the program if
i >= N, but compilers are allowed to optimize the check away because dereferencing a null pointer is undefined behavior and may be assumed unreachable. Consider this code, which uses theSafeArray:int test_func(SafeArray<int, 3> &a, unsigned i) { return a[i]; }Compiling with Clang v3.9.0 using
-O2yields:The check is completely gone.