Sign in to follow this  

When and why should I use SIMD? Is it really worth?

This topic is 3493 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

You should use it when you have lots of data to apply the same operations to. This is common when working with matrices and vectors. It's much, much faster than normal float code.

Share this post


Link to post
Share on other sites
Then, its highly recommended to use it in a simple vector class? I mean, its really much faster to do a simple addition of two vectors? And about memory alignment? What you have to say?

Share this post


Link to post
Share on other sites
In any case, manually coding SIMD should be left to a last resort type scenario. Most compilers have optimization flags that will compile some trivial code into SSE/SSE2/3DNOW. I know the MSVC compiler has these options.

EDIT: if you do incorporate SIMD, you have to align the class/variables. If your using MSVC, its as easy as adding a __declspec(align(16)) in front of your class declaration.

Share this post


Link to post
Share on other sites
Quote:
Original post by RealMarkP
In any case, manually coding SIMD should be left to a last resort type scenario. Most compilers have optimization flags that will compile some trivial code into SSE/SSE2/3DNOW. I know the MSVC compiler has these options.

EDIT: if you do incorporate SIMD, you have to align the class/variables. If your using MSVC, its as easy as adding a __declspec(align(16)) in front of your class declaration.


In my experience using the MSVC compiler flags causes visual studio to use the scalar sse instructions and not the packed versions. Ive never seen a packed instruction used when looking at the assembler output. Having verified the speed with profiling, its much faster to use sse by writing the assembly or using intrinsics when you can take advantage of the packed instructions rather than use the compiler flags.

Share this post


Link to post
Share on other sites
You use them when you have a problem that can be most efficiently translated to vector operations.

(SIMD) Vectorization is a process which allows you to perform multiple identical instructions on several distrinct values at once. For problems which can be solved this way, it's the most natural way to do more work in same time.

Assuming that we have two arrays of ints, and we want to compute pair-wise difference between the two. While a for loop will work, it will subtract two values at a time. With vectorization, you can perform difference between n values at the same time, for the same cost, making it n-times faster.

Unfortunately, effective use of these techniques is complex, requires forethought, custom algorithms, and fine-tuning.

Quote:
Most compilers have optimization flags that will compile some trivial code into SSE/SSE2/3DNOW. I know the MSVC compiler has these options


Yes, they can use those opcodes, but no compiler is capable of restructuring source code into vector-friendly code, with a few small exceptions. It's akin to knowing the syntax of a language, but it doesn't mean one can write efficient code in it.

From what I've seen, MVC doesn't do anything noteworthy, in some cases, the data type conversions will even slow down the code.

Intel's compiler is often cited as considerably better in this respect.

Share this post


Link to post
Share on other sites

This topic is 3493 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this