C++ – SSE SSE2 and SSE3 for GNU C++


Is there a simple tutorial for me to get up to speed in SSE, SSE2 and SSE3 in GNU C++? How can you do code optimization in SSE?

Best Answer

Sorry don't know of a tutorial.

Your best bet (IMHO) is to use SSE via the "intrinsic" functions Intel provides to wrap (generally) single SSE instructions. These are made available via a set of include files named *mmintrin.h e.g xmmintrin.h is the original SSE instruction set.

Begin familiar with the contents of Intel's Optimization Reference Manual is a good idea (see section for an example of intrinsics) and the SIMD sections are essential reading. The instruction set reference manuals are pretty helpful too, in that each instruction's documentation includes the "intrinsic" function it corresponds to.

Do spend some time inspecting the assembler produced by the compiler from intrinsics (you'll learn a lot) and on profiling/performance measurement (you'll avoid wasting time SSE-ing code for little return on the effort).

Update 2011-05-31: There is some very nice coverage of intrinsics and vectorization in Agner Fog's optimization PDFs (thanks) although it's a bit spread about (e.g section 12 of the first one and section 5 of the second one). These aren't exactly tutorial material (in fact there's a "these manuals are not for beginners" warning) but they do rightly treat SIMD (whether used via asm, intrinsics or compiler vectorization) as just one part of the larger optimization toolbox.

Update 2012-10-04: A nice little Linux Journal article on gcc vector intrinsics deserves a mention here. More general than just SSE (covers PPC and ARM extensions too). There's a good collection of references on the last page, which drew my attention to Intel's "intrinsics manual".