MMX and SIMD optimization question

Started by
1 comment, last by Adam_42 12 years, 4 months ago
Hi, just wanted to know, when optimization is turned on (in a c++ program), will the compiler try to optimize for MMX or SSE if possible? or do you always have to do this by hand?
Advertisement

Hi, just wanted to know, when optimization is turned on (in a c++ program), will the compiler try to optimize for MMX or SSE if possible? or do you always have to do this by hand?


It depends on the compiler. But "modern" compilers should be able to optimize for it if the corresponding flags are set. At the same time, those are the kind of optimizations where you cannot assume the compiler will do it better than a competent programmer by hand. Often "handoptimizing" better than the compiler is very hard. But when it comes to the SIMD my experience is that the compiler will only be able to do it in the most obvious cases.
To be more specific VS 2010 will use some SSE/SSE2 instructions if you pick the appropriate setting, but it won't automatically use the SIMD instructions at all. The latest beta does do some auto vectorization. You can see some more details at http://virtualdub.org/blog/pivot/entry.php?id=353

I believe recent versions of gcc can also do some auto vectorization, but I'm not sure how well it works.

In performance critical code using either SSE intrinsics or assembly directly is your best option at the moment. However intrinsics and assembly are much more awkward to write and maintain, so I'd only use them where profiling finds there's a significant bottleneck that could be improved a lot with SIMD.

This topic is closed to new replies.

Advertisement