LWN: Comments on "An Introduction to GCC Compiler Intrinsics in Vector Processing (Linux Journal)" https://lwn.net/Articles/517237/ This is a special feed containing comments posted to the individual LWN article titled "An Introduction to GCC Compiler Intrinsics in Vector Processing (Linux Journal)". en-us Mon, 13 Oct 2025 13:20:10 +0000 Mon, 13 Oct 2025 13:20:10 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net An Introduction to GCC Compiler Intrinsics in Vector Processing (Linux Journal) https://lwn.net/Articles/519060/ https://lwn.net/Articles/519060/ khim <blockquote><font class="QuotedText">tl;dr: the dispatch has overhead and the folks who need vector math either don't care about CPU portability or refuse to accept that overhead.</font></blockquote> <p><a href="http://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Function-Attributes.html#index-g_t_0040code_007bifunc_007d-attribute-2529">GCC dispatching</a> is tied to shared libraries and have <b>no</b> overhead on top of that. Nothing. <b>Exactly zero</b>. Not one single cycle, not one single byte (except for the slow-path which is, obviously, not a big concern: it's called slow-path for a reason). Sure, shared libraries are slower for various reasons yet somehow games use them, but they don't use dispatch. <b>Where is the logic</b> in your statement? Why would you create fully separate engine where you can only create specialized version of some core part?</p> <p>IMNSHO it's not "refuse to accept", it's "refuse to consider because of ignorance". Ignorance is most definitely <b>not</b> bliss in this particular case.</p> Wed, 10 Oct 2012 05:19:11 +0000 An Introduction to GCC Compiler Intrinsics in Vector Processing (Linux Journal) https://lwn.net/Articles/519014/ https://lwn.net/Articles/519014/ elanthis <div class="FormattedComment"> I'm not convinced it's useful at all.<br> <p> There are largely three classes of applications that really make use of these features:<br> <p> 1) HPC apps, where portability of a binary is not necessary since the whole system is generally compiled for a very specific set of hardware.<br> <p> 2) Media processing apps, which generally offload to the GPU these days, because even the best CPU ops for media processing are slow compared to a 300-2000 core GPU (which might even have specialized circuitry for certain media processing tasks, like video encode/decode).<br> <p> 3) Games (the parts that can't be offloaded to the GPU, or for games where the graphics alone are consuming the GPU's processing bandwidth), which are often mixing in bits and pieces of vector code with non-vector code and in which the overload of dispatch to another routine completely negates the advantage of using the vector instructions in the first place.<br> <p> In the last case, there are games that just compile the core engine multiple times for different common end-user CPU architectures into shared libraries, and use a small loader executable to select and load the proper shared library. This allows the vector math to be completely inlined as desired while still allowing use with newer instruction sets like SSE4.1, while the game still runs on older baseline SSE3 hardware. Note that we don't generally bother supporting folks without SSE3 even on x86, since nobody who plays high-end games has a CPU old enough to lack SSE3. (Steam Hardware Survey: 99.18% of PC gaming users have SSE3, but only 57.41% have SSE4.1, so SSE3 is baseline supported but SSE4.1 must still be optional in apps.)<br> <p> tl;dr: the dispatch has overhead and the folks who need vector math either don't care about CPU portability or refuse to accept that overhead.<br> </div> Tue, 09 Oct 2012 18:35:38 +0000 An Introduction to GCC Compiler Intrinsics in Vector Processing (Linux Journal) https://lwn.net/Articles/517510/ https://lwn.net/Articles/517510/ nix <blockquote> Perhaps this can be made simpler at the GCC level? Some kind of attribute which you can attach to you function to say "I need versions for Atom, Bulldozer, Core2, K8, K10, and Pentium4 - with automatic switch to pick one of them at runtime". </blockquote> You can do this with a library, a couple of #defines, and IFUNC. However, for smaller operations this is actually harmful because the hit from the indirection through the PLT exceeds the time spent in the function. (Note that since glibc itself avoids use of the PLT for internal calls, its own calls to memcpy() et al do not benefit from IFUNC at all, and always go to a maximally-generic routine. The cost of this seems to be minimal.) Tue, 25 Sep 2012 11:49:08 +0000 An Introduction to GCC Compiler Intrinsics in Vector Processing (Linux Journal) https://lwn.net/Articles/517421/ https://lwn.net/Articles/517421/ dashesy <div class="FormattedComment"> And Intel's IPP when used as dynamic library (and upon calling &lt;i&gt;ippInit&lt;/i&gt;) dispatches based on CPU automatically.<br> </div> Mon, 24 Sep 2012 18:29:07 +0000 An Introduction to GCC Compiler Intrinsics in Vector Processing (Linux Journal) https://lwn.net/Articles/517408/ https://lwn.net/Articles/517408/ khim <p>Good point. Note that recent versions of GCC and GLibC support <a href="http://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Function-Attributes.html#index-g_t_0040code_007bifunc_007d-attribute-2529">the dispatching</a>.</p> <p>Perhaps this can be made simpler at the GCC level? Some kind of attribute which you can attach to you function to say "I need versions for Atom, Bulldozer, Core2, K8, K10, and Pentium4 - with automatic switch to pick one of them at runtime".</p> <p>Intel's compiler does something like this but few guys use it in production...</p> Mon, 24 Sep 2012 16:39:26 +0000 An Introduction to GCC Compiler Intrinsics in Vector Processing (Linux Journal) https://lwn.net/Articles/517363/ https://lwn.net/Articles/517363/ bluebugs <div class="FormattedComment"> The main problem of auto vectorization and any vectorization logic done at compilation time is that it only target one kind of CPU. Handling the switch logic at runtime (required for any packaged application supposed to run on many hardware), require a lot of hack into the build system to produce each possible optimized loop. So very few project do that...<br> </div> Mon, 24 Sep 2012 01:06:17 +0000 An Introduction to GCC Compiler Intrinsics in Vector Processing (Linux Journal) https://lwn.net/Articles/517335/ https://lwn.net/Articles/517335/ ssam <div class="FormattedComment"> Its even better if you can get the compiler to do a good job of autovectorising your code. That way it is portable to new architectures. I found this article the other day <a href="http://locklessinc.com/articles/vectorize/">http://locklessinc.com/articles/vectorize/</a> . It has a a few examples of how GCC autovectorises, why sometimes it thinks that it can't, and how to convince it that it can.<br> </div> Sun, 23 Sep 2012 12:22:21 +0000 An Introduction to GCC Compiler Intrinsics in Vector Processing (Linux Journal) https://lwn.net/Articles/517281/ https://lwn.net/Articles/517281/ iwillneverremember <div class="FormattedComment"> Another approach is ORC <a href="http://code.entropywave.com/orc/">http://code.entropywave.com/orc/</a><br> * I haven't tried it myself.<br> <p> </div> Sat, 22 Sep 2012 06:45:09 +0000 An Introduction to GCC Compiler Intrinsics in Vector Processing (Linux Journal) https://lwn.net/Articles/517279/ https://lwn.net/Articles/517279/ gmaxwell <div class="FormattedComment"> Meh. Closed source libraries with free software incompatible licenses. Not my idea of stellar advice.<br> </div> Sat, 22 Sep 2012 01:45:27 +0000 An Introduction to GCC Compiler Intrinsics in Vector Processing (Linux Journal) https://lwn.net/Articles/517257/ https://lwn.net/Articles/517257/ dashesy A really nice article I wished for a few years ago. Although instrinsics prevent going all the way to assembly there are still some gotchas like placing <i>__builtin_ia32_emms</i> here and there to avoid some floating point corner cases. Also in its simplest usage it requires fixed vector length for the processing path. Not the best approach since new CPUs come with larger vector support; this emphasizes the need for dynamic dispatching based on CPU (or better would be a <a href=http://lwn.net/Articles/489337/>mixed approach</a> that also considers GPU). <p> Overall the advice given in paragraph before the summery seems to be the most practical one: <blockquote><font class=QuotedText>Fourth, don't re-invent the wheel. Intel, Freescale and ARM all offer libraries and code samples to help you get the most from their processors. These include Intel's Integrated Performance Primitives, Freescale's libmotovec and ARM's OpenMAX.</font></blockquote> </p> Fri, 21 Sep 2012 21:34:25 +0000