GCC: Difference between -O3 and -Os

The GCC documentation describes what these options do very explicitly. -O3 tries to optimize code very heavily for performance. It includes all of the optimizations -O2 includes, plus some more. -Os, on the other hand, instructs GCC to “optimize for size.” It enables all -O2 optimizations which do not increase the size of the executable, … Read more

boost spirit V2 qi bug associated with optimization level

It’s a bug in your code, nothing wrong with the compiler or the optimization levels. The cinch is with expression templates (like the ones used by Boost Proto, and hence by Boost Spirit). They are only valid to the end of their enclosing full expression [1] The canonical workaound is: BOOST_SPIRIT_AUTO(ana, *~qi::char_(‘*’) > +qi::char_(‘*’)); You … Read more

No speedup when summing uint16 vs uint64 arrays with NumPy?

TL;DR: I made an experimental analysis on Numpy 1.21.1. Experimental results show that np.sum does NOT (really) make use of SIMD instructions: no SIMD instruction are used for integers, and scalar SIMD instructions are used for floating-point numbers! Moreover, Numpy converts the integers to 64-bits values for smaller integer types by default so to avoid … Read more

Are floating point operations in C associative?

The compiler is not allowed to perform “optimizations”, which would result in a different value computed, than the one computed according to abstract machine semantics. Program execution [#1] The semantic descriptions in this International Standard describe the behavior of an abstract machine in which issues of optimization are irrelevant. [#3] In the abstract machine, … Read more

How to turn off gcc compiler optimization to enable buffer overflow

That’s a good problem. In order to solve that problem you will also have to disable ASLR otherwise the address of g() will be unpredictable. Disable ASLR: sudo bash -c ‘echo 0 > /proc/sys/kernel/randomize_va_space’ Disable canaries: gcc overflow.c -o overflow -fno-stack-protector After canaries and ASLR are disabled it should be a straight forward attack like … Read more

Why does GCC generate 15-20% faster code if I optimize for size instead of speed?

By default compilers optimize for “average” processor. Since different processors favor different instruction sequences, compiler optimizations enabled by -O2 might benefit average processor, but decrease performance on your particular processor (and the same applies to -Os). If you try the same example on different processors, you will find that on some of them benefit from … Read more