4 ms·
Not surprising, after all C doesn't have vector math. There is no way to make sensible use of these instructions without the compiler significantly altering the
by josefx 4y ago
Not surprising, after all C doesn't have vector math. There is no way to make sensible use of these instructions without the compiler significantly altering the program flow first.
- klodolph 4y agoUsing -O3 is a very sensible way to use vector instructions, in practice. It’s not universally good. It’s just that if you take naïve C code that does bulk operations on arrays, and compile it at -O3, you might get a very nice improvement from the auto-vectorizer. With some additional restrict keyword annotations, you can sometimes improve the performance significantly. Then there are non-standard tricks you can use, like __builtin_assume_aligned(). This is something of an arcane art. Sometimes it just doesn’t work at all, sometimes it’s not obvious how to write your code so that the autovectorizer can work well, and getting the autovectorizer to work requires enabling various code transformation passes that will often make code worse. However, it’s still worth using, because when your function does autovectorize well, it saves you a ton of work trying to vectorize it manually.
- rep_movsd 4y agoActually, if you tell the compiler to use SSE and above, it will use them extensively and even for floating point instead of x87
- josefx 4y agoYes, it will do fun things like turn 1.0f + 1.0f into (1.0f,0,0,0) + (1.0f,0,0,0), that is better than having to deal with the old floating point stack, but doesn't really exploit the full potential of SSE instructions.
- SotCodeLaureate 4y agoSSE has scalar instructions - like "addss", "subss" etc. These will be used by default (at O2 without vectorization enabled) for single-precision floating point math on x86-64 (where stack-based FPU is deprecated). Vector instructions you're referring to end with "ps", they're very unlikely to be emitted for typical fp operations.