4 ms·
The subset that most have is going to be pretty broad. These days, you'd definitely assume that processors have SSE2, for example. However, most SSE2 instructi
by klodolph 4y ago
The subset that most have is going to be pretty broad. These days, you'd definitely assume that processors have SSE2, for example.
However, most SSE2 instructions won't be emitted by GCC until you crank things up to -O3.
- duskwuff 4y ago> These days, you'd definitely assume that processors have SSE2, for example. In fact, x86_64 specifically guarantees the availability of SSE2.
- josefx 4y agoNot 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.
- masklinn 4y agoThese are completely unrelated issues. Vectorising non-vector C code is difficult (and likely relies on other expensive optimisations around flow control manipulation). And it’s not a “sure fire” optimisation because the compiler can absolutely vectorise a loop whose 99p is an iteration or two making the vectorisation a complete waste of compilation and runtime. So being an expensive and not perfectly reliable optimisation, it makes sense for it to be at O3. That has nothing to do with ISA subsetting/compatibility.
- klodolph 4y agoIt sounds like we agree on everything here, but I’m not sure what you are saying is a “completely unrelated issue”.